+ 1
I don't understand why (==) is use instead of (!=) And why is (%) is used instead. Please explain it for me. Code in description
#include <iostream> using namespace std; int main() { int number; cin>>number; // your code goes here if (number %2==0){ cout << "even"; } else { cout <<"odd"; } return 0; }
4 ответов
+ 3
This is the definition of an even number. If a number is divisible by 2 without a remainder, it is an even number. % is a division operator with a remainder.
+ 1
Just to add a bit more Alexey's statement..
% is a modulo operator. The result is the remainder from the division.
ie:
15 % 12 = 3
15 / 12 = 1.25
15 % 12 is derived by:
15 / 12 = 1 with 3 left over from long division.
0
Thank you