Learn Programming
Learning new Things
Sum of digits program in Python
Sum of digits program
in
Python
Program:
sum=0;m=0;
n=int(input("Enter a number:"))
while(n>0):
m=n%10;
sum=sum+m;
n=n//10;
print("Sum is ",sum)
OutPut:
Enter a number:654
Sum is 15
Enter a number:123
Sum is 6
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment