Question : How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....)
We can find a number is odd or even by a simple programmain(){int a[2],i;a[0]=0; //0--means Even Numbera[1]=1; //1--means Odd numberscanf("%d",&i);printf("%d",a[i%2]);getch();}
By taking a character array its still simple. main(){ char a[2][5]={"EVEN","ODD"}; int i;
main() ( int a,b,c; printf("Enter the number"); scanf("%d", &a); b=a%2; c=b*2; if(a=c) printf("The number is even"); else Printf("The number is odd"); }
union u1 { int i; char c; }u2; u2.i=32767; u2.c='a'; now the i value gets replaced. If we want to know the data that is saved in the union..internally, without knowing what values that we are using in the prog.
that is if just want to know whether a union currently holds an int or a char? If it is a combination of both int and char..we must know even that. and the memory locations at which this data is stored?