CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
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....)


Category C Interview Questions
Rating (4.4) By 7 users
Added on 7/18/2006
Views 2162
Rate it!
Answers:

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;

scanf("%d",&i);
printf("%s",a[i%2]);
getch();
}



 Posted by: Syed Baseer Ahmed    

Contact Syed Baseer Ahmed  Contact Syed Baseer Ahmed

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");
}



 Posted by: Lakshmi.N    

Contact Lakshmi.N  Contact Lakshmi.N

This can done using switch statement

Switch(num%2)
{
Case 1:
Printf(?This is a odd number?);
Break;
Case 0:
Printf (?This is a even Number?);
}



 Posted by: hari    

Contact hari  Contact hari

num%2?printf("This is Odd number"):printf("This is even number");



 Posted by: Prudhvi Raj Kumar M    

Contact Prudhvi Raj Kumar M  Contact Prudhvi Raj Kumar M

Use ternary operatos:

void main()
{
int a;

printf(" Enter an integer number: ");
scanf("%d",&a);

((a%2)==0)?printf(" Even"):printf(" odd");

getch();
}



 Posted by: james    

Contact james  Contact james

just make use of ternary operator:

#include<stdio.h>
#include<conio.h>

void main()
{
int a;
printf(" enter an integer number:");
scanf("%d",&a);

((k%2)==0)?printf(" %d is even",a):printf(" %d is odd",a);
getch();
}



 Posted by: james    

Contact james  Contact james

void main()
{
int a;
printf("enter the number ");
scanf("%d",&a);
((a%2)==0))?
printf("even"):printf("odd");
gech();
}



 Posted by: sattibabu    

Contact sattibabu  Contact sattibabu

To find Odd or Even With out using if, while or for
main()
{
int a;
scanf("%d",&a);
(a%2)?printf("Odd Number"):printf("Even Nember);
}



 Posted by: PM Karthick    

Contact PM Karthick  Contact PM Karthick


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What will be the output of the following program in UNIX OS with CC compiler and TC compiler?

int main()
{
int i=5;
printf(" %d",++i + ++i + ++i + ++i + ++i );
}
If any difference then Why it is difference?


View Answer
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?


View Answer
When function say abc() calls another function say xyz(), what happens in stack?

View Answer
How to remove duplicate elements from an array

View Answer
main(int x).............

explaination on arguments passed thr' main

View Answer
How do you write a C program which can calculate lines of code but not counting comments?

View Answer
How to swap the content of two variables without a temporary variable

View Answer
Output of this Programme please??

main()
{

int a[]={2,4,6,8,10};
int i;
change(a,5);
for(int i=0;i<=4;i++)
printf(" %d", a[i]);
}

change(int *b,int n)
{

int i;
for(i=0;i *(b+i) = *(b+i)+5;
}

sytaxis correct?? was asked i a test


View Answer
Can we use string in switch statement?

View Answer
How can you calculate number of nodes in a circular Linked List?

View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/5967/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.66