0
Help can't uderstand
why is What is the value of the result variable? int a = 12; int b = 5; int result = a % b; 2?
5 Answers
+ 3
% gives remainder
As a=12, b=5.
Result=a%b; means 12%5 =2.
As 5*2 + 2=12.
2 is remainder here.
+ 2
%(module) -- it will give the remainder
/ --- it will give the qufficient value
ex:
a=12;
b=6;
R=a%b;
S=a/b;
Output:
R=0
S=2
+ 2
You can think, that 12 % 5 subtracts 5 from 12 until the result is less than 5, but more than or equal to 0.
12 % 5:
12 - 5 = 7
7 - 5 = 2
Now the result is less than 5 but more than or equal to 0, so the result is 2.
24 % 7:
24 - 7 = 17
17 - 7 = 10
10 - 7 = 3
Result is 3, because 3 is less than 7, but more than or equal to 0.
+ 1
5 goes into 12 2 times to reach 10.
The remainder is 2.
The operation only wants the remainder.
0
What is the value of the result variable?
int a = 12;
int b = 5;
int result = a % b;