http://acm.hdu.edu.cn/showproblem.php?pid=1013
解题分析
24 ------》 2+4=6-------------》6<=10-------------》输出6
38------------》3+8=11----------》11>=10------------》1+1=2----------------》输出2
就这样我在写这段代码时候考虑用递归来着,但是吧先发一个普通的方法,再优化一下就在发上来
#include <stdio.h>
int f(int);
main(){
int sum,n;
scanf("%d",&n);
sum=f(n);
if(sum>=10){
printf("%d",f(sum));
}else{
printf("%d",f(n));
}
}
int f(int x){
int single,ten,s;
single=x/10;
ten=x%10;
s=ten+single;
return s;
}