0

How it will work..??

i=n%10; sum=sum+i;/*sum=o*/ n=n/10;

8th Sep 2018, 1:45 PM
Sowmiya
Sowmiya - avatar
5 Answers
+ 7
say n = 25 the % modulo operator returns the remainder if two numbers are divided unequally. So i = n % 10 ---> i = 25 % 10 i = 5 sum = sum + i ---> 0 = 0 + 5 sum = 5 n = n / 10 ---> 25 = 25 / 10 n = 2 on next iteration i = 2 % 10 i = 2 sum = 5 + 2 sum = 7
8th Sep 2018, 2:01 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
sowmiya its because whenever the number to the left of modulo operator is less than the number to the right of modulo operator, the answer will always be equal to the number that is on the left side of modulo operator That's why i = 2 % 10 ---> i = 2
8th Sep 2018, 8:38 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
my doubt is cleared...thanks bro..
8th Sep 2018, 2:05 PM
Sowmiya
Sowmiya - avatar
0
i=2%10...HOW IT BECAME I=2..???
8th Sep 2018, 2:47 PM
Sowmiya
Sowmiya - avatar
0
yes bro..i understood... tanq..
9th Sep 2018, 3:27 AM
Sowmiya
Sowmiya - avatar