find a number whether it is even or odd without using any
control structures and relational operators?

Answers were Sorted based on User's Feedback



find a number whether it is even or odd without using any control structures and relational operato..

Answer / ramya

A number anded with the lower number that is n & (n - 1) =
0 then it is even if it is anything else it is odd

odd_even (int n)

{
if (!(n & (n -1))
number is odd
else
number is even

}

Is This Answer Correct ?    9 Yes 29 No

find a number whether it is even or odd without using any control structures and relational operato..

Answer / guest

#include<stdio.h>
#include<conio.h>
void main()
{
int x;
if(x%2==0)
printf("even");
else
printf("odd");
getch();
}

Is This Answer Correct ?    4 Yes 25 No

Post New Answer

More C Interview Questions

What are types of structure?

0 Answers  


main() { int arr[5]={23,67}; printf("%d%d%d",arr[2],arr[3],arr[4]); }

9 Answers   TCS,


What are the types of pointers?

0 Answers  


What is cohesion in c?

0 Answers  


How pointer is different from array?

0 Answers  


Is c dynamically typed?

0 Answers  


Not all reserved words are written in lowercase. TRUE or FALSE?

0 Answers  


What is the purpose of sprintf() function?

0 Answers  


Where local variables are stored in c?

0 Answers  


What is the meaning of this decleration? unsigned char (*pArray[10][10]); please reply.

1 Answers  


c program for searching a student details among 10 student details

0 Answers  


You have an int array with n elements and a structure with three int members. ie struct No { unsigned int no1; unsigned int no2; unsigned int no3; }; Point1.Lets say 1 byte in the array element is represented like this - 1st 3 bits from LSB is one number, next 2 bits are 2nd no and last 3 bits are 3rd no. Now write a function, struct No* ExtractNos(unsigned int *, int count) which extracts each byte from array and converts LSByte in the order mentioned in point1.and save it the structure no1, no2, no3. in the function struct No* ExtractNos(unsigned int *, int count), first parameter points to the base address of array and second parameter says the no of elements in the array. For example: if your array LSB is Hex F7 then result no1 = 7, no2 = 2, no3 = 7. In the same way convert all the elements from the array and save the result in array of structure.

2 Answers   Qualcomm,


Categories