C Program to find the sum of digits in the given number

#include<stdio.h>
int main()
{
    int number;
    printf("Enter the number\n");
    scanf("%d",&number);
    int sum=0,rem;
    while(number!=0)
    {
        rem=number%10;
        sum=sum+rem;
        number=number/10;
    }
   printf("The sum of digits is: %d",sum);
}

Output:

C Program to find the sum of digits in the given number



Comments