+ 2

pls give explanation {r=n%10; s=s+r; n=n/10} this program in sum of the digit

solve this function

4th Apr 2017, 12:08 PM
Goudham Ram
Goudham Ram - avatar
11 Antworten
+ 4
this program will get the sum of each digit I'm the number if number is 1987 sum = 1+9+8+7 = 25
4th Apr 2017, 12:19 PM
Heng Jun Xi
Heng Jun Xi - avatar
+ 4
n = 1987 s = 0 r = 1987 % 10 = 7 s = 0 + 7 = 7 n = 1987 / 10 = 198 r = 198 % 10 = 8 s = 7 + 8 = 15 n = 198/10 = 19 r = 19%10 = 9 s = 15 + 9 = 24 n = 19/10 = 1 r = 1%10 = 1 s = 24 + 1 = 25 n = 1/10 = 0
4th Apr 2017, 12:24 PM
Heng Jun Xi
Heng Jun Xi - avatar
+ 3
the first line will just get the number of the last digit second line at the number into sum third line will get rid of the last digit in the number for next operation These three lines of code needs to be done in loop for the condition while(n!=0)
4th Apr 2017, 1:07 PM
Heng Jun Xi
Heng Jun Xi - avatar
0
sum of the digit { r=n%10; s=s+r; n=n/10; } pls explain this function
4th Apr 2017, 12:27 PM
Goudham Ram
Goudham Ram - avatar
0
do {digit= n % 10; n = n / 10; M = M* 10 + digit;} while (n > 0);
5th May 2021, 6:43 AM
Cherry Charg
Cherry Charg - avatar
0
n%10
30th Oct 2022, 5:46 AM
Sravani
0
1%10
30th Oct 2022, 5:47 AM
Sravani
0
5%10
30th Oct 2022, 5:47 AM
Sravani
0
2%10
30th Oct 2022, 5:47 AM
Sravani
0
Temp//=10
30th Oct 2022, 5:56 AM
Sravani
0
How to write temp//=10
30th Oct 2022, 5:56 AM
Sravani