(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Program to find the sum of digits in a number and to count the number of digits in the number - TecGlance

Header Ads

Program to find the sum of digits in a number and to count the number of digits in the number


Program to find the sum of digits in a number and to count the number of digits in the number

a=input("Enter any number : ")
sum=0
i=0
while a>0:
    re=a%10
    sum+=re
    a=a/10
    i=i+1
else:
    print"Sum of the digits in the number is ",sum
    print"The number of digit in the number is ",i

OUTPUT :

Enter any number :  123
Sum of the digits in the number is  6
The number of digit in the number is  3
  
Enter any number :  53
Sum of the digits in the number is  8
The number of digit in the number is  2

No comments

Powered by Blogger.