Sum of The Digits 10 :- Given an integer between 0 and 10000, write a program to print the sum of its digits.

PHOTO EMBED

Sun Oct 27 2024 06:55:52 GMT+0000 (Coordinated Universal Time)

Saved by @developercampus #training #onlinetraining #placement

def sum_of_digits(number):
    sum = 0
    while number > 0:
        digit = number % 10
        sum += digit
        number = number // 10
    return sum

# Example usage
number = 12345
print("Sum of the digits:", sum_of_digits(number))
content_copyCOPY

Explanation For example, if the given number is 45, your code should print the sum of the digits (4+5), which is 9. Similarly, if the given number is 762, your code should print the sum of the digits (7+6+2), which is 16. Similarly, if the given number is 9988, your code should print the sum of the digits (9+9+8+ 8), which is 34.
https://fullstackdevelopercampus.in/