PAT甲级1002
#include<iostream>using namespace std;int main(){int a,sum = 0,num;cin>>a;while(a != 0){num = a % 10;sum =sum + num;a = a/10;}//int sum1,sum2,sum3;//sum1 ...
·
#include<iostream>
using namespace std;
int main()
{
int a,sum = 0,num;
cin>>a;
while(a != 0)
{
num = a % 10;
sum =sum + num;
a = a/10;
}
//int sum1,sum2,sum3;
//sum1 = sum/100;
//sum2 = (sum - 100*sum1)/10;
//sum3 = sum % 10;
cout<<sum<<endl;
return 0;
}
会输出46因为int值表示范围问题
更多推荐
已为社区贡献1条内容
所有评论(0)