# Plz solve my problem !

• 01-15-2003
pankaj8096
Plz solve my problem !
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 ?
• 01-15-2003
Polymorphic OOP
• 01-15-2003
i think no one is going to code you the whole program.
show some effort!
• 01-15-2003
Govtcheez
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.
• 01-15-2003
minesweeper
I'd probably know what one was if I saw it but as far as jargon goes, what's a control statement?
• 01-15-2003
Cela
>>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.
• 01-15-2003
Travis Dane
*sniff sniff* *sniff sniff* i smell homework, hmm......
• 01-15-2003
penney
Untested
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]);
}
• 01-15-2003
ronin
Ouch..... you guys are so harsh. :D

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; }```
• 01-15-2003
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.
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; }```
• 01-15-2003
ronin
Quote:

Originally 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.

Hmph.... those picky profs :D
• 01-15-2003
TCL
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; }```
• 01-16-2003
optical
Here
#include <stdio.h>

int main(void)
{
int InputNumber=0;
int ReturnFunction=0;
char junk;

scanf("%d", &InputNumber);

ReturnFunction = (InputNumber%2);

if (ReturnFunction==0)
{
printf("\nThe Number is Even")
}
else
{
printf("\nThe Number is Odd")
}

getchar(junk);

return 0;
}