Computer Science, asked by afinf2006, 1 month ago

Write a program using function to print the sum of digits of a number. The result must be returned back to main()

Answers

Answered by Anonymous
1

This ur anwer i hope it helps u

Attachments:
Answered by poojan
11

Printing the sum of the digits of a number.

Language used: Python Programming

Program:

#called function

def sumofdigits(x):

   #initializing sum value to 0

   sumvalue=0

   #Iterating till all the digits in the number gets completed

   while x!=0:

       #taking the last value

       remainder=x%10

       #updating the x value by removing the one that is already taken

       x=x//10

       #adding the value taken to the sum.

       sumvalue = sumvalue + remainder

   #returning the summation value

   return sumvalue

if __name__=="__main__":

   #taking the input

   x=int(input())

   #calling the function for the summation; print the return value

   print(sumofdigits(x))

Input:

5320

Output:

10

Learn more:

Write a statement to add a Key: Value Pair of 7:49 to dictionary  D={1:1,3:9,5:25}

brainly.in/question/43499112

Your friend and you made a list of topics and both of them voted if they like or dislike the topic. They wrote 0 to denote dislike and 1 to denote like..

brainly.in/question/44681897

Attachments:
Similar questions