数位之和

给定一个整数n,输出n的各位数字之和。


#include<iostream>
using namespace std;
int main()
{
int n,m=0,s=0;
cin>>n;
do{
m=n%10;
s=s+m;
n=n/10;
}while(n%10!=0||n/10!=0); 
cout<<s;
return 0;

posted @ 2022-03-14 18:17  青城墨白  阅读(39)  评论(0编辑  收藏  举报