1 //输入一个整型值(无符号),把它转换成字符并打印它,前导0被删除 
2 #include<stdio.h>
3 #include<stdlib.h>
4 void binary_to_ascii(unsigned int value);
5 int main()
6 {
7 unsigned int i;
8 printf("please input a value:\n");
9 scanf("%d",&i);
10 binary_to_ascii(i);
11 system("pause");
12 return 0;
13 }
14 void binary_to_ascii(unsigned int value)
15 {
16 unsigned int quotient;
17 quotient=value/10;
18 if(quotient!=0)
19 binary_to_ascii(quotient);
20 putchar(value%10+'0');
21 }

此处是递归应用的一个例子,对于数值转换成字符,递归是一个很好的办法。

posted on 2011-12-04 13:13  candyming  阅读(596)  评论(0编辑  收藏  举报