Our social:

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: ");
    scanf("%d",&num);
    sum = 0;
    temp = num;
    while(temp!=0){
        sum = sum + temp % 10;
        temp = temp / 10;
    }
    printf("\n");
    printf("The sum of the digits of %d is %d",num,sum);
    return 0;
}

Share it with your friends if you have liked this.