#include <iostream>
using namespace std;
int main()
{
int x, a, b, c, d;
int s = 0;
cout << "请输入一个四位数整数:" ;
cin >> x;
a = x % 10;
b = x / 10 % 10;
c = x / 100 % 10;
d = x / 1000 % 10;
s = a + b + c + d;
cout <<"每位数相加之和为:"<< s << endl;
system ("pause");
return 0;
}
Last modification:December 5th, 2018 at 07:41 pm
© 允许规范转载