/*求一个数各个位上的数字之和*/ |
#include<iostream> |
using namespace std; |
int main() |
{ |
printf ( "请输入一个正整数!\n" ); |
int x,n=0; |
cin>>x; |
int s=0; |
while ( x ) |
{ |
s+=x%10; |
x/=10; |
n++; |
} |
printf ( "各个位上的数之和是:\n" ); |
cout<<s; |
printf ( "\n" ); |
return 0; |
} |