**C Program to find sum of all digits** in a number is a simple to program.

To calculate the sum of digits first we need to separate out each digit in number then add digits in Number. We use the %( modulus) operator to separate out digits in the number.

## Algorithm to find sum of all digits in number

- Take the input number. No
- While no > 0

Separate out digit digit =no%10;

Calculate sum= sum + digit - Remove the first digit from a number or to get remaining number no = no/10;
- Print Sum of digits in a number

## C Program to find sum of all digits in number

#include<stdio.h> void main() { int dummy,n,sum=0,x; printf("Enter a number\n"); scanf("%d",&n); dummy=n; while(n>0) { x=n%10; sum=sum+x; n=n/10; } printf("The sum of all digits in %d is %d\n",dummy,sum); }

**Output :**