#include "stdafx.h"
#include <ioStream.h>int getSum(int n)
{
if(n < 10)
return n; int temp(10), sum(0), a(0);
while (n > temp)
{
temp *=10;
} temp /=10; while (temp > 0)
{
sum += n/temp;
n -= (n/temp) * temp;
temp /= 10;
}
return sum;
}int main(int argc, char* argv[])
{
int n = 4235;
cout << "the sum is: " <<getSum(n)<< "\n";
return 0;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货