Problem Solving: Sum of Digits
Learn to write a sum of digits program using the concepts we have learned so far.
Now that we’ve covered most of the basics, we will be learning to solve different problems. In this lesson, we will think of a solution together to write a program that takes a number and calculates the sum of its digits.
So let’s get to it!
Sum of digits
Write and run a digits summation program (using operators +, %, /) that takes a six-digit integer from the user and prints the sum of its six digits.
Sample Input:
123456
Sample output:
21
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy