Sunday, May 10, 2009

Finding Even of Odd without decission statements.

This is a program in C to find whether the given number is an even or odd number. But no decission making statements (like if, if-else, switch, while etc..) are employed.

void main()

{

int n;

printf("Enter the n value: ");

scanf("%d",&n);

char res[2];

res[0]='e';

res[1]='o';

printf("%c",res[n%2]);

getch();

}

Output:

Enter the n value: 10

E

here E stands for even number and

O stands for Odd number

No comments:

Post a Comment