一行一个正整数,不知道有几位数,反正不超过int,需要用到循坏。比较麻烦。
这题我会代码马上发你
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int ans=0;
while(n)
{
ans+=n%10;
n/=10;
}
cout<<ans<<endl;
return 0;
}
参考:https://www.cnblogs.com/cswuyg/archive/2012/02/03/2336424.html