find a number whether it is even or odd without using any
control structures and relational operators?
Answers were Sorted based on User's Feedback
Answer / vinocit
#include<stdio.h>
int main()
{
int n=10000;
char *s[2]={"Even","Odd"};
printf("%s",s[n&1]);
return 0;
}
Is This Answer Correct ? | 47 Yes | 11 No |
Answer / vinothkumar.r
But its much efficient just to find whether the last bit is
0 or 1
Is This Answer Correct ? | 16 Yes | 2 No |
Answer / d.c.sathishkumar
#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 ? | 17 Yes | 8 No |
Answer / shashi
#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 ? | 11 Yes | 2 No |
Answer / vignesh1988i
the first answer is excellent .... superb..... this is what
i expected........ marvalous.......... congrats
thank u
Is This Answer Correct ? | 10 Yes | 5 No |
Answer / vamsi
#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 ? | 13 Yes | 8 No |
Answer / vignesh1988i
mind you sir == is an relational operator.................
thank u
Is This Answer Correct ? | 5 Yes | 1 No |
Answer / abhradeep chatterjee
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 ? | 5 Yes | 1 No |
Answer / ruchi
#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 ? | 5 Yes | 1 No |
Answer / ramesh
#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 | 1 No |
What is the difference between NULL and NUL?
What is a pointer value and address in c?
What is main () in c language?
declare afunction pointer to int printf(char *)?
How to reverse a string using a recursive function, without swapping or using an extra memory?
31 Answers Cisco, Mind Tree, Motorola, Ophio, Sony, TCS, Wipro,
What is uint8 in c?
why java is called as a purely oops language.
What is a pointer in c plus plus?
Explain data types & how many data types supported by c?
I want tcs placement papers of 2004-2009 , its urgent
praagnovation
What is time null in c?