Even/Odd Program in C
write an program in C to find whether a given input number is EVEN or ODD
Condition :- do not use conditional statement(if,while) ,ternary operator(?)
only use printf and scanf statement and arithmetic operator .
Example: input : Enter number- 22
output : Even
Condition :- do not use conditional statement(if,while) ,ternary operator(?)
only use printf and scanf statement and arithmetic operator .
Example: input : Enter number- 22
output : Even
Replies
-
cooltwinsdiclaimer:i am no computer genius. i just did c during 1st year and here is my idea...๐
#include
void main()
{
printf("\n enter the number:");
scanf("%d",&n);
int l=0;
l=n%2;
for(;l=0; )
printf("\n EVEN");
for(;l=1; )
printf("\n ODD");
}
this is prone to errors.... -
raj87verma88@Techno: Do you mind sharing your own attempt at solving this question? It looks as if you want us to solve some assignment question for you. We do not tolerate this here.
@Cooltwin and Goyal: We do not provide free lunches. We help others but do not spoon feed the answers to them. -
techno_ishantya i'll raj... i have given this program in national level technical event held in over institute
and no one have solve this program
so here it is:-
main()
{
char *str[2]={"EVEN","ODD"};
int num;
printf("Enter Number :-");
scanf("%d",&num);
printf("%s",str[num%2]);
} -
mohammad yusufishan sir i have tried this code but didn't find the solution it has error in scanf statement
#include
void main()
{
printf("\n enter the number:");
scanf("%d",&n);
int l=0;
l=n%2;
for(;l=0; )
printf("\n EVEN");
for(;l=1; )
printf("\n ODD");
} -
suyash
Umm... I am not too sure that no one was able to solve this program if it was indeed a national level technical event ๐techno_ishantya i'll raj... i have given this program in national level technical event held in over institute
and no one have solve this program -
suyash
I guess the html encoding used in CE forums have goofed up the ampersand operator in the scanf statement. You should have at least edited the code before running it just like that by copy paste ๐mohammad yusufishan sir i have tried this code but didn't find the solution it has error in scanf statement
P.S.:- after editing the scanf statement, you might get one more error where the code is trying to divide the int variable by 2. ๐
You are reading an archived discussion.
Related Posts
We just got the news that Infosys is laying off its employees once again. This time, about 5-10% of the workforce may be laid off.
Its being said that the...
Well, uhh, the forum rules did say that the topic should be titled appropriately... ๐ *shot*
After looking through the other introduction posts, I wondered whether the template given in...
I don't mean to be a leecher right on the day I joined CE, but I'm a bit pressed on time for the completion of this task at the moment,...
hello friends i am rohit doing engineering in electrical & electronics branch.I need your help .I have to make a mini project within a week so can you please suggest...
A desperate woman writes to the Technical support Guy,
Dear Tech Support,
Last year I upgraded from Boyfriend 5.0 to Husband 1.0 and I noticed a distinct slowdown in the...