I don't understand why (==) is use instead of (!=) And why is (%) is used instead. Please explain it for me. Code in description | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

23rd Dec 2021, 5:03 PM
Musi Babila Bryant
Musi Babila Bryant - avatar
4 Answers
+ 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.
23rd Dec 2021, 5:08 PM
Alexey Kopyshev
Alexey Kopyshev - avatar
+ 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.
23rd Dec 2021, 6:55 PM
William Owens
William Owens - avatar
0
Thank you
23rd Dec 2021, 5:58 PM
Musi Babila Bryant
Musi Babila Bryant - avatar