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 does void main () mean?

0 Answers  


How can you increase the size of a dynamically allocated array?

0 Answers   TISL,


Hi, main() { } Is a user defined function or Built in Functionn

26 Answers   Honeywell, Yahoo,


write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.

6 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers   Mind Tree,






what is a far pointer

12 Answers   ABB, DRDO, ITI, Maruti Suzuki, Steel Plant, TCS, Toyota, Vivo Mobiles,


What are derived data types in c?

0 Answers  


how to write hello word without using semicolon at the end?

6 Answers   Accenture,


if the address of a[1,1] and a[2,1] are 1000 and 1010 respectively and each occupies 2 bytes then the array has been stored in what order?

4 Answers   Amazon, Apple, Bata, Google, NASA,


How can I recover the file name given an open stream?

0 Answers  


Why main is not a keyword in c?

0 Answers  


What oops means?

0 Answers  


Categories