0

How to write this condition?

i want to write it in code... condition is " if given number is divisible by two". eg: if(condition) { cout{ //statement} else {//statement}

28th Sep 2018, 3:19 AM
Mubarak Hussain
Mubarak Hussain - avatar
2 Réponses
+ 7
if (number % 2 == 0)
28th Sep 2018, 4:37 AM
Aleksander Szczepura
Aleksander Szczepura - avatar
+ 1
You use the “modulus” operator (%), which divides by two and returns the remainder of the division. Then you check that there is no remainder, indicating that the number was evenly divisable by two ((number % 2) == 0)
28th Sep 2018, 6:55 AM
Ross Drew
Ross Drew - avatar