Given a five-digit integer, print the sum of its digits.
The modulo operator, %, returns the remainder of a division. For example, 4 % 3 = 1 and 12 % 10 = 2. The ordinary division operator, /, returns a truncated integer value when performed on integers. For example, 5 / 3 = 1. The Modulo operator can be used to get the last digit of a number in base 10. Given a five-digit integer, print the sum of its digits.
Input Format
The input contains a single five-digit number.
Output Format
Print the sum of the digits of the five-digit number.
Constraints
10,000 <= n <= 99,999
C Program
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, sum=0,rem;
scanf("%d", &n); //Enter the number
while(n>0)
{
sum=sum+(n%10); //Calculating the sum
n/=10; //Removing the last digit
}
printf("%d\n",sum);
return 0;
}