7-127 Sum of the digits (6分)
7-127 Sum of the digits (6分)
Given a none-negative number, print out the sum of its digits.
Input Format:
A none-negative integer number.
Output Format:
The sum of its all digits.
Sample Input:
123
Sample Output:
6
#include<stdio.h>
int main()
{
int n;
int sum=0;
scanf("%d",&n);
while(n)
{
sum+=n%10;
n/=10;
}
printf("%d\n",sum);
return 0;
}

浙公网安备 33010602011771号