im new to programming but how can i prove that am integer is even. cause i need ot make a program the says if the number that was inputed is either even or odd. thanks in advance.
Just thought I'd mention what the modulus operator does, in case you don't already know.
When you divide two integers, the modulus is the remainder that you get. So for example, if you divide any even number by 2, you should get a remainder of 0. That's why you check to see if foo%2 == 0. If the value of foo was odd, the remainder would be 1.
#include <iostream.h>
main() {
int foo;
cout << "Enter a number: ";
cin >> foo;
if(foo%2 == 0)
cout << "The number is even \n";
else
cout << "The number is odd \n";
return 0;
}
Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.