The sum of the digits of a positive integer (the decomposition process of the number)

#include<cstdio>
using namespace std;
int main()
{
    
    
int n,s=0;
scanf("%d",&n);
do{
    
    
s+=n%10;
n/=10;
}
while(n!=0);
printf("%d\n",s);
return 0;
}

Guess you like

Origin blog.csdn.net/qq_51082388/article/details/112102031