hdoj1013

来源:互联网 发布:网络推广任务 编辑:程序博客网 时间:2024/05/21 11:03

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;}


0 0
原创粉丝点击