- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C program to find sum of digits of a five digit number

Suppose we have a five-digit number num. We shall have to find the sum of its digits. To do this we shall take out digits from right to left. Each time divide the number by 10 and the remainder will be the last digit and then update the number by its quotient (integer part only) and finally the number will be reduced to 0 at the end. So by summing up the digits we can get the final sum.

So, if the input is like num = 58612, then the output will be 22 because 5 + 8 + 6 + 1 + 2 = 22.

To solve this, we will follow these steps −

- num := 58612
- sum := 0
- while num is not equal to 0, do:
- sum := sum + num mod 10
- num := num / 10

- return sum

## Example

Let us see the following implementation to get better understanding −

#include <stdio.h> int main(){ int num = 58612; int sum = 0; while(num != 0){ sum += num % 10; num = num/10; } printf("Digit sum: %d", sum); }

## Input

58612

## Output

Digit sum: 22

- Related Articles
- C++ program to find sum of digits of a number until sum becomes single digit
- Find last five digits of a given five digit number raised to power five in C++
- Program to find sum of digits until it is one digit number in Python
- Finding sum of digits of a number until sum becomes single digit in C++
- C# program to find the sum of digits of a number using Recursion
- Digit sum upto a number of digits of a number in JavaScript
- C++ Program to Sum the digits of a given number
- Java Program to Find Sum of Digits of a Number using Recursion
- Reduce sum of digits recursively down to a one-digit number JavaScript
- 8086 program to find sum of digits of 8 bit number
- 8085 program to find sum of digits of 8 bit number
- The sum of digits of a two-digit number is 8. If 36 is added to the number then the digits reversed. Find the number.
- Maximum of sum and product of digits until number is reduced to a single digit in C++
- A two-digit number is 4 times the sum of its digits and twice the product of the digits. Find the number.
- A two digit number is 4 times the sum of its digits and twice the product of its digits. Find the number.

Advertisements