To find whether a number is even or odd without using any
conditional operator??

Answers were Sorted based on User's Feedback



To find whether a number is even or odd without using any conditional operator??..

Answer / mohd adnan

/* By Mohd Adnan MCA(2007-10) IMS Ghaziabad */
/* by using bit wise operator*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("Enter any number:");
scanf("%d",%num);
(num&1)&&printf("Odd Number");
((num&1)==0)&&printf("Even Number");
getch();
}

Is This Answer Correct ?    37 Yes 15 No

To find whether a number is even or odd without using any conditional operator??..

Answer / amala v

import java.io.*;

public class even {
public static void main(String arg[])throws IOException
{
String a[]={"even","odd"};
int p;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter a number to find:");
int n=Integer.parseInt(br.readLine());
p=n%2;
System.out.println("The Number is :"+a[p]);


}
}

Is This Answer Correct ?    24 Yes 7 No

To find whether a number is even or odd without using any conditional operator??..

Answer / naveen

main ()
{
int num;
if ( num & 1 )
printf ("num is odd number\n");
else
printf ("num is even number\n");
}

Is This Answer Correct ?    21 Yes 13 No

To find whether a number is even or odd without using any conditional operator??..

Answer / jai gomathi

/*PROGRAM BY JAI GOMATHI.NS, B.E.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
char a["oddnumber","evennumber"];
printf("\nEnter a number: ");
scanf("%d",&n);
printf("%s",a[n%2]); //when odd, a[1] will print odd number
getch();
}

Is This Answer Correct ?    9 Yes 3 No

To find whether a number is even or odd without using any conditional operator??..

Answer / azad sable,chiplun.

void main()
{
int n;
clrscr();
printf("enter any no.");;
scanf("%d",&n);
if(n%2==0)/*remainder after division by 2*/
printf("\nthe no. is even");
else
printf("\nthe no. is odd");
}
getch();
}

Is This Answer Correct ?    10 Yes 9 No

To find whether a number is even or odd without using any conditional operator??..

Answer / amala v

friends

u are using if condition in program.. u should not use
that.because the question is without any condition. if is
also a condition ok. so try to find without if .

Is This Answer Correct ?    4 Yes 4 No

To find whether a number is even or odd without using any conditional operator??..

Answer / umair jatoi && zain ja

/* ZAIN JATOI AND UMAIR JATOI */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf("Enter any number:");
scanf("%d",&n);
if(n&1)
printf("%d is Odd number",n);
else
printf("%d is even number",n);
getch();
}

Is This Answer Correct ?    2 Yes 2 No

To find whether a number is even or odd without using any conditional operator??..

Answer / rudrakshala leela phani kumar

int main()
{
int a[2][5]={"Even","Odd"};
int n;
printf("Enter Integet No:");
scanf("%d",&n);
printf("\nResult:%d",a[n%2]);
}

Is This Answer Correct ?    1 Yes 2 No

To find whether a number is even or odd without using any conditional operator??..

Answer / yogeshkumar

Check given number is even or odd without using modulo operator.
for this we use & operator.
if any number is odd it must have right most bit 1.
example:
int i=5;
binary form i= 0101
now use & operator
int j=i&1;[0101&1]//
here j have 0001;

public class EvenandOddNumber {
public static void main(String[] args) {
int i=5;
int j=i&1;
if(j>0){
System.out.println("odd");
}
else {
System.out.println("even");
}
}
}

Is This Answer Correct ?    0 Yes 1 No

To find whether a number is even or odd without using any conditional operator??..

Answer / mukul garg

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

Is This Answer Correct ?    13 Yes 16 No

Post New Answer

More C Interview Questions

What is 1f in c?

0 Answers  


write a progrmm in c language take user interface generate table using for loop?

0 Answers  


What is the mean of this statement:: if(int i=0 * i=9)

2 Answers   HCL,


how to get the starting address of file stored in harddisk through 'C'program.

2 Answers   Siemens,


why do we use # in c-language?

1 Answers  


what is the purpose of the code, and is there any problem with it. unsigned int v[10]; unsigned int i = 0; while (i < 10) v[i] = i++;

2 Answers   Google,


What is the most efficient way to count the number of bits which are set in an integer?

0 Answers  


Give me the code of in-order recursive and non-recursive.

0 Answers   DELL,


What is the difference between typedef and #define?

0 Answers  


In which mode we open the file for read,write and append also in c ? a)W b)w+ c)r+ d)a

2 Answers   BitWise,


which will be first in c compiling ,linking or compiling ,debugging.

3 Answers   Sonata,


Can you think of a way when a program crashed before reaching main? If yes how?

2 Answers  


Categories