# 2 – Best C program to find sum of all digits

## C program to find sum of all digits

To find sum of digits in c program first we have to accept number from user and modulus that number with 10 (this will give us last digit of original number).

Store reminder in one variable and then add reminder in result variable. (keep default value of result variable as 0).

Now to remove last digit from original number divide it by 10 and store it in same variable.

Carry same steps with remaining number and we will get our result.

`#include<stdio.h>int main() {     int x,rsl=0,y;     printf("Enter any number : ");     scanf("%d",&x);     while(x>0)     {         y=x%10;         rsl=rsl+y;         x=x/10;     }      printf("Result is = %d",rsl);     return 0; } `

Output :

Enter any number : 1234

Result is = 10

### Connect with us on following platforms

We are aiming to explain all concepts of C in easiest terms as possible.
ITVoyagers
Author

### 1 thought on “2 – Best C program to find sum of all digits”

1. Looking forward to reading more. Great blog article. Want more. Lucine Bob Brose