Tuesday , December 6 2016
Home / C / C program to Calculate Sum of Digits of a Number

C program to Calculate Sum of Digits of a Number

C Program to find Digit Sum:  The digit sum of a given integer number is the sum of all its digits. The source code given here are for two methods or rather tricks in C language.

Digit Sum Example:-  

Digit Sum of 12321 is calculated 1+2+3+2+1=9.
Digit Sum of 34236789754 is calculated 3+4+2+3+6+7+8+9+7+5+4=58.

We have also given the Solution of the problem Digit Sum Java Source code with two methods.

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.
  •  Output:-

    DigitSum

  • Output:-
    Input an integer
    123456789123456789
    Sum of digits of 123456789123456789 = 90

  • Output:-

    Input an integer
    12321
    Digit Sum=9

  • Just One line solution for Sum of the digits

  • Digit Sum Program in C

Also See:   C program for Sum of two number using While LOOP

Check Also

Hide Mouse Pointer C Program

How to Hide a Mouse Pointer Program in C : This program will show and hide ...

Leave a Reply

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

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