ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
find a number whether it is even or odd without using any
control structures and relational operators?
 Question Submitted By :: Vignesh1988i
I also faced this Question!!     Rank Answer Posted By  
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 1
#include<stdio.h>
int main()
{
	int n=10000;
	char *s[2]={"Even","Odd"};
	printf("%s",s[n&1]);
	return 0;
}
 
Is This Answer Correct ?    22 Yes 4 No
Vinocit
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 2
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 ?    4 Yes 17 No
Ramya
 
 
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 3
But its much efficient just to find whether the last bit is
0 or 1
 
Is This Answer Correct ?    8 Yes 0 No
Vinothkumar.r
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 4
the first answer is excellent .... superb..... this is what
i expected........ marvalous.......... congrats



thank u
 
Is This Answer Correct ?    4 Yes 1 No
Vignesh1988i
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 5
#include<stdio.h>
main()
{
 int n;
 char *p[]={"Even","odd"};
 Printf("Enter the number");
 scanf("%d",&n);
 n=n%2;
 printf("The value is %s",a[n]);

}
 
Is This Answer Correct ?    8 Yes 2 No
D.c.sathishkumar
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 6
#include<stdio.h>
main()
{
 int n;
 string p[2]={"Even","odd"};
 Printf("Enter the number");
 scanf("%d",&n);
 n=n%2;
 printf("The value is %s",p[n]);

}
 
Is This Answer Correct ?    7 Yes 1 No
Vamsi
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 7
THE LAST two answers posted by two folks are correct but the
declarations have been made wrong...... we cant make use of
1D array here , if so only 'e' or 'o' only will get
printed.... but that is not our aim... so correct
declaration is using a 2D array.....
char a[][6]={{"even"},{"odd"}};

and also it is not the must to make use of array of pointers
concept...........

thank u
 
Is This Answer Correct ?    0 Yes 0 No
Vignesh1988i
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 8
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
if(x%2==0)
printf("even");
else
printf("odd");
getch();
}
 
Is This Answer Correct ?    1 Yes 11 No
Guest
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 9
mind you sir == is an relational operator.................



thank u
 
Is This Answer Correct ?    1 Yes 0 No
Vignesh1988i
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 10
#include<stdio.h>
main()
{
 int n;
 string s[2]={"Even","odd"};
 Printf("Enter the number");
 scanf("%d",&n);
 n=n%2;
 printf("The value is %s",s[n]);

}
 
Is This Answer Correct ?    3 Yes 0 No
Shashi
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 11
ya. the first answer has impressed me.

#include<stdio.h>
main()
{
 int n;
 string p[2]={"Even","odd"};
 Printf("Enter the number");
 scanf("%d",&n);
 n=n%2;
 printf("The value is %s",p[n]);

}
 
Is This Answer Correct ?    2 Yes 0 No
Abhradeep Chatterjee
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 12
#include<stdio.h>
#include<conio.h>
main()
{
 int n;
 char *p[]={"Even","odd"};
 clrscr();
 printf("Enter the number");
 scanf("%d",&n);
 n=n%2;
 printf("The value is %s",p[n]);
 getch();

}
 
Is This Answer Correct ?    3 Yes 0 No
Ruchi
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 13
int oddeven(int n)
{
if(n&1)
return 1; //odd

else
return 0; //even
}
 
Is This Answer Correct ?    1 Yes 2 No
Asad
 
  Re: find a number whether it is even or odd without using any control structures and relational operators?
Answer
# 14
#include<stdio.h>
void main()
{
int p;
printf("number:");
scanf("%d",&p);
while(p%2)
{
printf("odd");
}
printf("even");
}
 
Is This Answer Correct ?    0 Yes 1 No
Satyanarayana
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
What is the output of the program given below #include<stdio.h> main() { char i=0; for(;i>=0;i++) ; printf("%d\n",i); } ADITI14
What are the average number of comparisons required to sort 3 elements?  2
Why preprocessor should come before source code?  2
What is function pointer and where we will use it NetApp1
what type of language is C? Microsoft2
how to display 2-D array elements in spiral  1
what is available in C language but not in C++?  1
if array a conatins 'n' elements and array b conatins 'n-1' elements.array b has all element which are present in array a but one element is missing in array b. find that element. Zycus-Infotech9
swap two integer variables without using a third temporary variable?  2
write a programe returns the number of times the character appears in the string  1
What's wrong with "char *p = malloc(10);" ?  4
What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?  1
why we shiuld use main keyword in C  5
Predict the output or error(s) for the following: 25. main() { printf("%p",main); } ME3
to find out the reverse digit of a given number Infosys5
x=2,y=6,z=6 x=y==z; printf(%d",x) HCL8
How would you sort a linked list?  1
what is the use of fflush() function?  1
study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above Accenture13
how do u find out the number of 1's in the binary representation of a decimal number without converting it into binary(i mean without dividing by 2 and finding out the remainder)? three lines of c code s there it seems...can anyone help  2
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com