Sum of the Digits of an Integer

Here is the C Program to find the sum of the digits of an integer.

#include <stdio.h>

int main()
    int num, temp, sum;
    printf("Enter a number: ");
    sum = 0;
    temp = num;
        sum = sum + temp % 10;
        temp = temp / 10;
    printf("The sum of the digits of %d is %d",num,sum);
    return 0;

Share it with your friends if you have liked this.