+ 2

What does % as math operator in C++?

Example: a = 16 % 3;

16th Dec 2022, 12:13 PM
Fishin' cat Bobby
Fishin' cat Bobby - avatar
2 Answers
+ 10
% đŸ‘ˆđŸ» this is a modulus operator and we use this operator for getting the remainder when we divide two numbers When 16 gets divided by 3 we get quotient 5 and remainder as : 1 So when we print : cout<< 16%3; We get 1 (which is a remainder) as output
16th Dec 2022, 12:24 PM
Suparna Das
Suparna Das - avatar
+ 2
Hi! The operator of the remainder of the number % (for example: 17 % 3 = 2) 1. Take the nearest number when divided by 3 would be zero. That's apparently 15 2. Subtract 15 from 17 and the result is your answer.
16th Dec 2022, 1:09 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar