This C Program computes the sum of digits in a given integer. This program m accepts integer. Then adds all the digits of a given integer, that becomes the sum of digits of integer.

Here is source code of the C program to compute the sum of digits in a given integer. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C program to accept an integer & find the sum of its digits`

`*/`

`#include <stdio.h>`

void main()

`{`

long num, temp, digit, sum = 0;

printf("Enter the number \n");

scanf("%ld", &num);

temp = num;

while (num > 0)

`{`

digit = num % 10;

sum = sum + digit;

num /= 10;

`}`

printf("Given number = %ld\n", temp);

printf("Sum of the digits %ld = %ld\n", temp, sum);

`}`

$ cc pgm81.c $ a.out Enter the number 300 Given number = 300 Sum of the digits 300 = 3 $ a.out Enter the number 16789 Given number = 16789 Sum of the digits 16789 = 31

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms>

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics of C, go to C Programming Examples.