Explore
ProGrad Programs
About Us

Edit
Reply




Edit

Program to Find the Sum of Digits of a Given Number | FACE Prep

Published on 10 Mar 2020

Program to find the sum of digits of the given number is discussed here. This problem can be solved in two methods: Iterative approach and Recursive approach

For example, let the input number be 719. The sum of digits of 719 = 7 + 1 + 9 = 17


Algorithm to find the sum of digits of a number


  • Input the number.
  • Declare a variable called sum and initialize it to 0.
  • while (number > 0)
  • Get the rightmost digit of the number using % operator by dividing it with 10 and add it to sum
  • Divide the number by 10.
  • Return sum


Program to find the sum of digits of a number (Iterative approach)


C
C++
Java
Python 3

Output
Enter a number : 12345
sum of digits of 12345 is : 15


Program to find the sum of digits of a number (Recursive approach)


C
C++
Java
Python 3

Output
Enter a number : 12345
sum of digits of 12345 is : 15


Recommended Programs








If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in