Help can't uderstand | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

24th Sep 2019, 1:53 PM
Ralph mira
Ralph mira - avatar
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.
24th Sep 2019, 2:24 PM
Mayank Matwa
+ 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
24th Sep 2019, 2:02 PM
๐Ÿ‘€ Sandy๐Ÿ‘€
๐Ÿ‘€  Sandy๐Ÿ‘€ - avatar
+ 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.
24th Sep 2019, 3:36 PM
Seb TheS
Seb TheS - avatar
+ 1
5 goes into 12 2 times to reach 10. The remainder is 2. The operation only wants the remainder.
30th Sep 2020, 8:12 PM
Zara Sharma
Zara Sharma - avatar
0
What is the value of the result variable? int a = 12; int b = 5; int result = a % b;
8th Jul 2023, 3:30 AM
KARTHIKRAJA R
KARTHIKRAJA R - avatar