# How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....)

Showing Answers 1 - 46 of 46 Answers

#### srilatha

• Feb 16th, 2006

we can use for loop.

like for(i=1 ;  i%2 != 0 ;i++)

printf("no i is odd",i);

Was this answer useful?  Yes

#### kannan

• Feb 17th, 2006

We can use Conditional Operator
size=1>printf(n%2==0,"Even","Odd");

Was this answer useful?  Yes

#### Srikanth M.N

• Feb 19th, 2006

can we use conditional operator (i%2==0)?even:oddif there is nay answer pz let me know

Was this answer useful?  Yes

#### Sreenath Reddy

• Feb 22nd, 2006

we can find a number is odd or even by a simple programmain(){int a,i;a=0; //0--means Even Numbera=1; //1--means Odd numberscanf("%d",&i);printf("%d",a[i%2]);getch();}

Was this answer useful?  Yes

#### corwin

• Feb 25th, 2006

please, don't pay attention to synthax, i don't know C, C++ very well, I'm trying to explain the idea by this code. I assume that function i called "mod" takes the fractional part of division and numb is the number to be checked. I assume that you have compiler that supports exception handling.function check_even_odd(int numb) {dbl dummy;try dummy= 1/mod(numb) print('Odd') //i don't know correct operator to do it in Cexcept //catch divide by zero exception here (i don't know the operators) print('Even') //i don't know correct operator to do it in C end;}

Was this answer useful?  Yes

#### brnprasad Profile Answers by brnprasad

• Mar 1st, 2006

We can use the & operator.

if(n&0x1) {

printf("Its Odd");

}

else

printf("Even");

Was this answer useful?  Yes

#### chandu

• Mar 2nd, 2006

we can use conditional operator ternary.

Was this answer useful?  Yes

#### ganapathy

• Mar 2nd, 2006

void main()

{

char a[]={"even","odd"};

scanf("%d",&n);

printf("%s",a[n%2]);

}

#### VishalJais Profile Answers by VishalJais

• Mar 10th, 2006

#include<stdiio.h>

#include<conio.h>

void main()

{

clrscr();

printf("\n Enter the number");

scanf("%d",&i);

switch(i%2)

{

case 0:

printf("\n %d is Even",i);

break;

case 1:

printf("\n %d is Odd",i);

break;

} //End of Switch()

getch();

}  //End of main()

#### Prashant

• Mar 17th, 2006

(n&1) ? printf("Odd") : printf("Even") ;

#### Casanova Profile Answers by Casanova

• Mar 18th, 2006

a still funkier solutionint main(){ int i; scanf ("%d",&i); printf ("EVEN\0ODD"+((i%2)*5)); return 0;}

Was this answer useful?  Yes

#### Nagaraju

• Mar 20th, 2006

How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....)

Since i used Conditional Operator. It is the simplest Solution.

(i%2==0)?printf("Given Number is Even: %d",i):printf("Odd:%d",i);

#### bala nagi reddy

• Mar 22nd, 2006

Hi, The solution is very simple.every odd number will have 1 in the least significant bit in the binary format.so the solution is to find the least significant bit and that can be found by right shifting the number by 1 bit and using ternary operation to print the result. Any prob with my solution please let me know by email.Thanks,bala

Was this answer useful?  Yes

#### samarem Profile Answers by samarem

• Mar 31st, 2006

plz will u explain wat does this statement mean:n&0x1

u can mail me at manish.kumar007@hotmail.com

Was this answer useful?  Yes

#### Munish

• Apr 14th, 2006

Every odd number has its least significant digit as 1. so if we check a number for the presence of 1 as the LSB then we can know if its a odd number or not. ANDing gives the solution to our problem 11001& 00001 ------------ 00001------------The result will be one only if last bit is one i.e no is odd.

Was this answer useful?  Yes

#### haripanda

• Apr 17th, 2006

as u haveto check thenumber is / even at the entery level so

printf("enterthe number");

scanf("%d",&n);

swich(n%2)

{

case 0:

printf("even");

break;

case 1:

printf("ood");

}

Was this answer useful?  Yes

#### Praveen Kumar M

• May 4th, 2006

main()
{
int n=4;
printf( (5*(n%2))+"Even\x00Odd");
}

Was this answer useful?  Yes

#### veena

• Jun 15th, 2006

main()

{

int a,b;

char even,odd;

printf("enter the no");

scanf("%d",&a);

b=(a%2?"odd":"even");

printf("%s",b);

}

#### Vinit

• Jun 25th, 2006

Use showbits()

Check the last bit, if it is 1 its Odd else its Even.

Was this answer useful?  Yes

#### K N

• Jun 29th, 2006

Here is one moreprintf(num%2==0? "even":"odd");

Was this answer useful?  Yes

#### ercans Profile Answers by ercans

• May 12th, 2008

void isNumberEven(int Number)
{
char StringArray;
strcpy(&(StringArray),"EVEN");
strcpy(&(StringArray),"ODD");

printf("%d is %s n",Number, &(StringArray[Number%2]));

}

Was this answer useful?  Yes

#### jintojos Profile Answers by jintojos

• May 22nd, 2008

// Finding Odd/Even Number Without If Clause
#include
#include
void main()
{
int num,rem;
printf("Enter The Number :");
scanf("%d",&num);
rem=num%2;
while(rem)
{
printf("Odd Number..");
getch();
exit(0);
}
printf("Even Number....");
getch();
}

Was this answer useful?  Yes

#### amar_keerthi07 Profile Answers by amar_keerthi07 Questions by amar_keerthi07

• May 24th, 2008

Let n be a number. Now this may be the answer :

n%2?printf("even"):printf("odd");

This is almost possible since its not a conditional operator.

Its a ternery operator (?:) that evaluates a condition or expression..

Was this answer useful?  Yes

#### bnaffas Profile Answers by bnaffas

• May 27th, 2008

char** answer = { 'odd', 'even' };
return answer[number & 0x1];

Was this answer useful?  Yes

#### paragmalshe Profile Answers by paragmalshe

• May 29th, 2008

int isOdd(int num){
return (num&1);
}
//logical anding is done with the last bit of the no. all the bits except last //1 are masked. which wud determine whther no. is even or odd.

Was this answer useful?  Yes

#### Gitabalakrishnan Profile Answers by Gitabalakrishnan

• Jun 6th, 2011

modulus operator can be used.

if (i%2)
printf("Even");
else
printf("Odd");

Regards,
Geetha B

Was this answer useful?  Yes

#### cageordie Profile Answers by cageordie

• Jun 17th, 2011

Assuming i contains the number we wish to evaluate...

char *oddeven[] = {"even", "odd"};
printf("number is %sn",oddeven[i%2]);

Was this answer useful?  Yes

#### shweta

• Sep 13th, 2014

(i%2==0)?even:odd

Was this answer useful?  Yes

#### alok kumar

• Nov 12th, 2014

// to check entered number is odd or even without using modulus or for or while or switch etc...//

```Code// by alok kumar
#include<stdiio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
printf("
Enter the number");
scanf("%d",&i);
j=i/2;
if(i==j)
printf("
Entered number is even");
else
printf("
Entered number is odd ");
getch();
}  //End of main()```

```Code#include<stdiio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
printf("
Enter the number");
scanf("%d",&i);
j=i/2;
if(i==j)
printf("
Entered number is even");
else
printf("
Entered number is odd ");
getch();
}  //End of main()```

Was this answer useful?  Yes

#### jbode Profile Answers by jbode Questions by jbode

• Nov 14th, 2014

See attached snippet. Creates a 2-element array with the strings "even" and "odd". Picks the string based on the result of the % operator (0 for even, 1 for odd), and prints the result. Does not use any sort of conditional statement or expression.

```Codechar *even_or_odd[] = {"even", "odd"};
int val;
scanf( "%d", &val );
printf( "%d is %s
", val, even_or_odd[val % 2] );```

Was this answer useful?  Yes

#### elayaraja.v

• Dec 17th, 2014

```Code#include<stdio.h>
main(){
int n;
puts("Enter the Number");
Scanf("%d",&n);
(n%2==0)?"Even":"Odd";

}```

Was this answer useful?  Yes

#### Mithun Agarwal

• Mar 4th, 2015

Hello,
I have a small concern. The above snippets is purely based on c programming language. Appreciate it would be great if you can assist me the same snippet using coldfusion components
Regards,
Mithun Agarwal

Was this answer useful?  Yes

#### ashik

• Mar 8th, 2015

Even

```Code#include <stdio.h>
int main()
{
int n;
printf ("plz input a number");
scanf ("%d",&n);
if (n%2==0)
{
printf ("EVEN")
}
else
{
printf ("ODD");
}
retrun 0;
}```

Was this answer useful?  Yes

#### Blinkk

• Mar 9th, 2015

Can you plz explain Printf statement?

Was this answer useful?  Yes

#### Muhammad Ali

• Mar 18th, 2015

If we use switch statement then without any loop, if, if..else we can find whether it is even or odd.

Was this answer useful?  Yes

#### Vikas

• Apr 4th, 2015

using switch statement this can be achieved using the and operator

Was this answer useful?  Yes

#### WASIM

• Apr 8th, 2015

(num%2==0)?printf("Even"):printf("Odd");{/geshibot}

Was this answer useful?  Yes

#### Kiran

• Feb 16th, 2017

I dont remember syntax of C
Ill give answer in Java

```Code// find a given number odd or even without any loop, if-else, switch, conditional statement.
int number = 41;
String[] array = {"Even", "Odd"};
System.out.println(array[(number%2)]);```

Was this answer useful?  Yes

#### Krishna

• May 30th, 2017

```Code#include<iostream>
int main()
{
int x;
cin>>x;
x%2?cout<<"odd"<<endl:cout<<"even"<<endl;
}```

Was this answer useful?  Yes

#### cageordie Profile Answers by cageordie

• Jun 6th, 2017

#include
#include
int main()
{
char *oddeven = {"even", "odd"};
int n;
printf("number: ");
fscanf(stdin, "%d", &n);
printf("Hello n is %s
", oddeven[n&1]);
return 0;
}

Was this answer useful?  Yes

#### pankajgupta2828 Profile Answers by pankajgupta2828 Questions by pankajgupta2828

• Aug 2nd, 2017

#include
#include
void main ()
{
int a;
printf("Enter the number -
");
scanf("%d",&a);
if (a%2)
printf("The number %d is odd
",a);
else
printf("The number %d is even
",a);
}

Was this answer useful?  Yes

#### Manoj Sah

• Aug 21st, 2017

Using & operator.

```Codemain()
{
int n;
printf("Ntr number:");
scanf("%d",&n);
if((n & 1 )== 0)
{
printf("Entred number is even:%d",n);
}
else
{
printf("Number is odd");
}
return 0;
}```

Was this answer useful?  Yes

#### harikrishna

• Oct 24th, 2017

Please can you explain this "printf( (5*(n%2))+"Evenx00Odd");" logic

Was this answer useful?  Yes

#### Chris

• Oct 28th, 2017

n%2 will give you 0 for even and 1 for odd. The string gives you the address of the start of the string. So for even it prints the string starting at the first character and for odd it starts at the 6th.

Was this answer useful?  Yes

#### RohitReddy Profile Answers by RohitReddy

• Mar 12th, 2018

You can use conditional operator like this,

String result = num % 2 == 0 ? "Even" : "Odd";

Was this answer useful?  Yes

#### Pujitha

• Jun 27th, 2019

We can use the conditional operator

Was this answer useful?  Yes

### Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.  