6 Respuestas
+ 9
a=int(input())
print(sum([int(x) for x in list(str(a))]))
+ 6
n=123;
sum=0;
while (n>0)
{
d=n%10; //for make the digit single
sum=sum+d; // for adding the digit which we get from d variable.
n=n/10; //to keep on making dividing the digit.
}
+ 5
Input from user
+ 2
#how to sum all the digits of a given number
num=str(input('Choose a number:'))
i=len(num)
sum=int(num[i-1])
while i>1:
i-=1
sum+=int(num[i-1])
print ("the sum of all the digits in",str(num),"is",str(sum))
+ 1
How to do that in JavaScript?
0
n=input('enter the digits you want: ')
p=n.split()
q=0
for i in n:
q=int(q)+int(i)
print('sum of digits is: ',q)