Sunday, July 26, 2009

Any one good at programming ?

i wanna write a program in borland c language when the user write a even number the program print this number is even and if else else print to the user this number is odd how i can make the computer characterize which is even and which is odd

Any one good at programming ?
Use the modulo (%) character. The modulo is like a division character but it only returns a 0 or 1.





0=no remainder


1=remainder





Example:


input: 67


------------------------------------


number = 67;





if((67%2)=0){


printf("the number %d is even", number);


}


else{


printf("the number %d is odd", number);


}





In the above example, when you express (67%2) this returns a 1 since there is a remainder. Therefore, 1=0 is a false statement and the program will print the line in the else block.
Reply:just another unique way would be:





int number;


//get input


if (number %26amp; 0x1)


printf("number is odd");


else


printf("number is even");
Reply:very simple...two ways to find it out...





you can take the mod % of the entered number by 2


if the answer is 1 then its an odd number, else its an even number





secondly you can divide the entered number with 2





if the result is integer...the number is even, if the result is float, the result is odd


No comments:

Post a Comment