C Program to Find and Print Sum of all Digit of any Number

« C Tutorial C Examples »

Here we will learn about how to create a program in C that will ask from the user to enter any number (at run-time) as input, and then calculate and print the sum of all the digit present in that given number. Here is the program:

int main()
    int num, sum=0, rem;
    printf("Enter any number: ");
    scanf("%d", &num);
        rem = num%10;
        sum = sum + rem;
        num = num/10;
    printf("\nSum of Digit = %d", sum);
    return 0;

As the program was written under Code::Blocks IDE, therefore after successful build and run, here is the output:

print sum of even digit c

Supply any number say 2358 and press ENTER key to see the sum of all the digit as output or result. Here is the second snapshot of the sample run:

print sum of all digit c

Here are the list of some main steps used in above program:

C Online Test

« C Tutorial C Examples »

© Copyright 2021. All Rights Reserved.