# c program sum of digits

devquora

Posted On: Dec 23, 2020

### Overview:

First of all in this article, I want to introduce you with number and its digits. Then I will demonstrate how to find the sum of its digits with the Logic to find sum of digits. After all, I will write c program to print the sum of digits of a number. After all, I will show Program output.

### What is Number?

Number is an arithmetical value, expressed by a word, symbol, or figure, representing a particular quantity and used in counting and making calculations. For example, 1243 has 4 symbols so we can say that 1243 is 4 digits number.

### Demonstration How to find the sum of its digits?

Suppose, We can consider 1243 as a number than its sum of digits will be 1+2+4+3 = 10 Other example, Consider integer 9876 then sum of digits = 9+8+7+6 = 30

### Logic to find the sum of digits of a number

To get sum of each digits by c program, use the following logic:

• Step 1: Get number by user, store it into variable number
• Step 2: Get the remainder of the number by using modulus operator
• Step 3: sum up the remainder of the number of each step
• Step 4: Divide the number by 10
• Step 5: Repeat the step 2 while number is greater than 0.

### C program to print the sum of digits of a number

```#include <stdio.h>
int main()
{
int number,sum=0,m;
printf("Enter a number of any digit:");
scanf("%d",&number);
while(number>0)
{
m=number%10;
sum=sum+m;
number=number/10;
}
printf("Sum of digits is = %d" , sum);
return 0;
}
```

Conclusion:

Number is an arithmetical value, expressed by a word, symbol, or figure, representing a particular quantity and used in counting and making calculations. In this Program first of all User Enter the an integer number then Program display the sum of digits of inputed number as an output.

Never Miss an Articles from us.

## Related Articles

#### C Program to convert Decimal to Binary Number

A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

#### C program to reverse a string

This program reversed the entered string that means opposite of the previous string sequence...

#### C program to reverse an Integer number

Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..