Thursday, July 30, 2009

HELP!! Turbo C problem ..?

here is the program i made for our homework. supposedly it should be able to allow an integer and tell wether it is an odd or an even.. but i dont know where did i go wrong. please help me.





main()


{


/*Variable Declaration*/


int I;


int ODD, EVEN;


clrscr();


printf("Odd/Even Program\n");


printf("____________________\n");


printf("Enter an integer:"); scanf("%d",%26amp;I);


if(I%3)


{


EVEN=I;


printf("%d is an even integer",EVEN);


}


if (I%2)


{


ODD=I;


printf("%d is an odd integer",ODD);


}


printf("__________________\n");


printf("Press any key to exit....");


getch();


}

HELP!! Turbo C problem ..?
The problem with your code is there are many integers which are divisible both by 2 %26amp; 3. For eg., if you give input as 6 to your code both the if loops will be skipped and no answer will be displayed. Jus change your code as:


if (I%2)


{


ODD=I;


printf("%d is an odd integer",ODD);


}


else


printf("%d is an odd integer",EVEN);
Reply:Just like the prev person stated the only thing it's opposite





if ( i%2 )


{


printf("%d is an even integer",%26amp;i);


}


else


{


printf("%d is an odd integer",%26amp;i);


}


No comments:

Post a Comment