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....)
Answer:
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();} Source: CoolInterview.com
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(); } Source: CoolInterview.com
Answered by: Syed Baseer Ahmed | Date:
| 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"); }
Source: CoolInterview.com
Answered by: Lakshmi.N | Date:
| 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”); } Source: CoolInterview.com
Answered by: hari | Date: 2/5/2008
| Contact hari
num%2?printf("This is Odd number"):printf("This is even number"); Source: CoolInterview.com
Answered by: Prudhvi Raj Kumar M | Date: 4/11/2009
| 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(); } Source: CoolInterview.com
Answered by: james | Date: 6/25/2009
| 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(); } Source: CoolInterview.com
Answered by: james | Date: 6/25/2009
| Contact james
void main() { int a; printf("enter the number "); scanf("%d",&a); ((a%2)==0))? printf("even"):printf("odd"); gech(); } Source: CoolInterview.com
Answered by: sattibabu | Date: 8/7/2009
| 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); } Source: CoolInterview.com
Answered by: PM Karthick | Date: 8/24/2009
| Contact PM Karthick
void main() { int n; clrscr(); printf("enter the no:=>"); scanf("%d",&n); (n%2==0)?printf("this is even"):printf("this is odd"); getch(); } Source: CoolInterview.com
Answered by: ansar husain | Date: 3/20/2010
| Contact ansar husain
#include<stdio.h> #include<conio.h> void main(void) { int num; clrscr(); printf(" Enter any number"); scanf("%d",&num);
num&1 ? printf(" Odd Number") : prinf(" Even Number"); }
Source: CoolInterview.com
Answered by: Aman Puri | Date: 4/9/2010
| Contact Aman Puri
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|