Write a C program to calculate the sum of all digits of a given integer.

#include<stdio.h>
main()
{
    int num,sum=0;
    printf("\nEnter a number=");
    scanf("%d",&num);
    while(num)
    {
        sum=sum+num%10;
        num/=10;
    }
    printf("\nThe sum =%d",sum);
}

No comments:

Post a Comment