0
why should we choose this % symbol? bcoz we are already have / so why??
7 Respostas
+ 5
% is an operator which gives remainder when two numbers are divided. Whereas / is a operator used to perform division and it gives the quotient.
0
% is the modulos operator which gives the reminder of a division, and / is the division symbol
0
The modulos // % // operator is fairly conventional across most languages, best make friends with it
0
thanks all
0
thanks
0
there are many uses for it, a simple common one is to check if a number is even or odd.
int main() {
int num;
cout << "Type in a number\n";
cin >> num;
if ((num % 2) == 0) {
cout << "The number is even\n";
} else {
cout << "The number is odd\n";
}
}
0
the modulus operator, %, outputs the remainder of two divided numbers, while the division operator,/, outputs the amount of times the smaller number(operand) is found in the bigger one. Yeah, that's easier