Each step of the loop will collect one digit ( right most ) by dividing the number with 10 and storing the reminder. Each time ( loop ) reminder we will add up by storing in a variable sum.

```
#include <stdio.h>
int main()
{
int n, sum = 0, remainder;
printf("Enter an integern");
scanf("%d",&n);
while(n != 0)
{
remainder = n % 10;
sum = sum + remainder;
n = n / 10;
}
printf("Sum of digits of entered number = %dn",sum);
return 0;
}
```

Your Rating

Swapping two numbers sample code
Average of two numbers as entered by user
Highest of three numbers
Finding exam Grade of mark entered using if else condition
Calculation of user entered numbers
Percentage of Mark
Division of Mark
Digits in Number
Sum of Digits
Matrix Multiplication

**Post Comment** This is for short comments only. for more discussions.