编写函数求一个正整数的各个位数上的数字之和。

#include
int pan(int x);
using namespace std;
void main()
{
int x,y;
cin >> x;
y = pan(x);
cout << y;
}
int pan(int x)
{
int y=0;
while (x > 0) {
y += x % 10;
x /= 10;
}return y;
}

你可能感兴趣的:(c++)