Hello freinds can any body solve my little problem:-
Make this prog in C---
Enter a number from keyboard and we have to tell weather this number is odd or even without using Control statements ?
Hello freinds can any body solve my little problem:-
Make this prog in C---
Enter a number from keyboard and we have to tell weather this number is odd or even without using Control statements ?
i think no one is going to code you the whole program.
show some effort!
I'd make 2 giant arrays, one containing all even numbers and one containing all odd numbers. If your number is in the odd array, it's odd. If it's in the even array, it's even.
-Govtcheez
[email protected]
I'd probably know what one was if I saw it but as far as jargon goes, what's a control statement?
>>I'd probably know what one was if I saw it but as far as jargon goes, what's a control statement?
if, switch, while, for, etc.
*Cela*
*sniff sniff* *sniff sniff* i smell homework, hmm......
void main(void)
{
char oddeven[][5]={"even","odd");
int number;
printf("Enter number:");
scanf("%d",&number);
printf("The number %d is %s",number,oddeven[number%2]);
}
Ouch..... you guys are so harsh.
See if this will work.
Code:#include <stdio.h> #include <assert.h> int main(void) { int num; printf("enter a number: "); scanf("%d", &num); assert(num > 0); printf("%d is %s", num, ((num % 2) == 0) ? "even" : "odd"); return 0; }
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
>>printf("%d is %s", num, ((num % 2) == 0) ? "even" : "odd");
I think the ?: operator counts as a control statement, penny was on the right track.
Code:#include <stdio.h> int main(void) { int num; char *eo[] = { "odd", "even", }; printf("Enter a number: "); fflush(stdout); /* Should test that sccanf works */ /* but that means using a control statement */ scanf("%d", &num); printf("%s\n", eo[num % 2 == 0]); return 0; }
*Cela*
Hmph.... those picky profsOriginally posted by Cela
>>printf("%d is %s", num, ((num % 2) == 0) ? "even" : "odd");
I think the ?: operator counts as a control statement, penny was on the right track.
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
Code:#include <stdio.h> int main(void) { int i; printf("enter a number: "); scanf("%d", &i); (i%2)&&printf("The number is odd\n"); (!(i%2))&&printf("The number is even\n"); return 0; }
#include <stdio.h>
int main(void)
{
int InputNumber=0;
int ReturnFunction=0;
char junk;
printf("Please Give Me a Number--->");
scanf("%d", &InputNumber);
ReturnFunction = (InputNumber%2);
if (ReturnFunction==0)
{
printf("\nThe Number is Even")
}
else
{
printf("\nThe Number is Odd")
}
getchar(junk);
return 0;
}