current position:Home>Input any large natural number and output the sum of each number. For example, input 12345, and the output result is: the sum of natural numbers 12345

Input any large natural number and output the sum of each number. For example, input 12345, and the output result is: the sum of natural numbers 12345

2022-01-27 01:58:19 CSDN Q & A

Enter any large natural number , Output the sum of each digit . For example, the input 12345, The output is : Natural number 12345 The sum of your numbers




Refer to the answer 1:
a=input()b=[int(i) for i in a]s=sum(b)print(s)



Refer to the answer 2:



Refer to the answer 3:
s = input()sum = 0for n in s:    sum += int(n)print(sum)



Refer to the answer 4:



Refer to the answer 5:
#include<stdio.h>#include<stdlib.h>int main() {    int n;    char str[1024];    scanf("%d", &n);    itoa(n,str,10);    int i = 0;    int res = 0;    while (str[i]!='\0')    {        res += (str[i]-'0');        i++;    }    printf("%d",res);    return 0;}



Refer to the answer 6:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270158177297.html

Random recommended