Tuesday , December 6 2016
Home / Python / Python program to calculate digit sum

Python program to calculate digit sum

Python program to calculate sum of the digits of a number here is a : This Source code for digit sum is calculated by getting the remainder and dividing each number by 10 in every iteration.

The digit sum of a given integer number is the sum of all its individual digits.

Example for digit sum:-

Digit Sum Program in Java

Digit Sum Iteration 1 :

  • 1894%10 = 4
  • 1894/10= 189
  • value of S = 0+ 4

Digit Sum Iteration 2 :

  • 189%10=9
  • 189/10= 18
  • Value of S=4+9

Digit Sum Iteration 3 :

  • 18%10=8
  • 18/10=1
  • Value of S=13+8

Digit Sum Iteration 4 :

  • 1%10=1
  • 1/10=0
  • Value of S= 21+1

Digit Sum Iteration 5 :

  • Terminates because of false Condition of loop.

You can also see a simple program on how to get sum of two number in C language.

  • Output:

    Enter any number to find the Digit Sum: 14353
    Digit Sum of 14353 is 16.

    Enter any number to find the Digit Sum: 123456789
    Digit Sum of 123456789 is 45.

  • Output:-

    Enter a number: 1694913782453266
    The Digit sum is 76

    Enter a number: 9876541
    The Digit sum is 40

Also See:   Python Program for Facebook Colored chat

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.