C++ Program to Calculate the Sum of Digits of a Number1 min read

We will write the sum of digits program in C++. Before that, you should have knowledge of the topics in C++ given below.

The program takes a user input for the integer whose sum of the digits needs to be found. Then using while loop, we will iterate the number and extract each digits and add it to the following one.

Lastly, we will display the sum of digits of that number. Let us go through the program.


C++ Program to Find Sum of Digits of a Number

In this program, we will use a while loop to iterate through the number. You can also do that using for loop.

C++ program to display the sum of the digits using a while loop.

Output:

Enter the Number: 123
Sum of Digits: 6


C++ Program to Calculate the Sum of Digits of a Number using for loop

Output: After successful execution of the above program, it will create the same output as the above one.


MORE

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More

Inverted Half Pyramid Pattern of Alphabets in C

In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in …
Read More