C++ Exercises: Compute the sum of the digits of an integer using function
84. Sum of the Digits of an Integer Using a Function
Write a C++ program to compute the sum of the digits of an integer using a function.
Visual Presentation:

Sample Solution:-
C++ Code :
Sample Output:
Compute the sum of the digits of an integer: ------------------------------------------------- Input any number: 255 The sum of the digits of the number 255 is: 12
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C++ program that defines a function to calculate the sum of digits of a number and calls it from main.
- Write a C++ program to implement a recursive function that returns the sum of the digits of an input integer.
- Write a C++ program that uses a separate function to compute and return the sum of the digits of a given number.
- Write a C++ program to create a function that iterates through the digits of a number and returns their sum, then print the result.
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to compute the sum of the digits of an integer.
Next: Write a program in C++ to reverse a string.
What is the difficulty level of this exercise?