[cpp] /********************************* * 日期:2013-1-27 * 作者:SJF0115 * 題號: 九度1106 * 題目:數字之和 * 來源:http://ac.jobdu.com/problem.php?pid=1106 * 結果:AC * 題意: * 總結: **********************************/ #include<stdio.h> #include<stdlib.h> //各位置數字之和 int Sum(int n){ int sum = 0; while(n){ sum += n % 10; n = n / 10; } return sum; } int main() { int n; //freopen("C:\\Users\\SJF\\Desktop\\acm.txt","r",stdin); while(scanf("%d",&n)!=EOF && n != 0) { int pow = n * n; printf("%d ",Sum(n)); printf("%d\n",Sum(pow)); } return 0; }