I know this is just a simple problem. I am new cprogramming student and I would like to know what and how I can incorporate the "%" function.
I know this is just a simple problem. I am new cprogramming student and I would like to know what and how I can incorporate the "%" function.
Make a program that finds all the even or odd numbers below a user-inputted number.
"%" is a so called "modulo" or as in school so called "remainder"....
i.e.
5 % 2 = 1...........
when you modulo (divide) 5 by 2... you see that two 2's fits in it making 4 and the remainder is 1......
One use is to test for an even number...
short int number = 5;
if (!(number % 2))
{
cout << "Even number!";
} else {
cout << "Odd number!";
}
for single line if (and maybe else) statements, you don't need the "{" and "}". Although, I could be wrong.
Hey thx for the help that really cleared things up.