Summation of the digits of a number (while loop)

0
Output

Explanation of the Digit Summation Program

This program calculates the sum of all digits of a number entered by the user. It repeatedly extracts the last digit of the number and adds it to a running total. The logic is implemented using a while loop and basic arithmetic operators.

Each iteration of the loop removes one digit from the number until no digits are left. The final result is the total summation of all digits in the input number.

What the Program Does

  • Asks the user to enter any number.
  • Extracts the last digit using num % 10.
  • Removes the last digit using num / 10.
  • Adds each digit to the variable sum.
  • Repeats the process until the number becomes zero.
  • Prints the final summation of all digits.
  • Uses getch() to pause the output screen (Turbo C feature).

Example Input

Enter a number: 753

Example Output

The summation is: 15

Summary: This program takes a multi-digit number, breaks it down digit by digit, adds all the digits together, and displays the total. It demonstrates the use of loops, arithmetic operations, and digit extraction techniques in C programming.

Tags

Post a Comment

0Comments

Post a Comment (0)