精彩百例:函数的递归调用
2015-03-28 11:20
399 查看
/* filename: the recursion function: convert the number to char */ # include <stdio.h> void convert_num(int num); int main(void) { int num; printf("Please input the number what you need convert: "); scanf("%d", &num); printf("\nThe number is %d.\n", num); /*if the number is negative ,add minus front of the number*/ if(num < 0) { putchar('-'); num = -num; } /*convert the number to char*/ printf("convertting the number .....\n"); convert_num(num); return 0; } /*convert the number to char*/ void convert_num(int num) { int i; if((i=num/10) != 0) convert_num(i); putchar((num%10)+'0'); } /* 递归: 当条件成立,进入第二层调用,当下一次条件成立,进入第三层调用 当条件不再成立,执行判断之后的语句,执行完之后,跳出最深层的函数(这里指第三层), 进入次一级的函数(这里指第二层), 一直这样循环,直到跳出所有的函数 */
result:
相关文章推荐
- 精彩百例:数组函数调用
- Java 学习笔记 (10) - Java 函数的递归调用
- 9.8 函数的递归调用
- 关于函数调用和尾递归的一点认识
- C++ && C# 函数的递归调用
- [java]函数的递归调用--代码举例
- 函数的递归调用与分治策略
- 快速排序 --递归调用一个函数初始值被写死
- 函数递归调用详解
- C++ primer 这本书上有这么两句话“派生类虚函数调用基类版本时,必须显式使用作用域操作符。如果派生类函数忽略了这样做,则函数调用会在运行时确定并且将是一个自身调用,从而导致无穷递归。”
- 用C语言解决(hanoi)汉诺塔问题——函数的递归调用
- 函数递归调用
- 函数的调用机制_用递归实现栈(Function call machenism_Recursive calls stimulate stack)
- 自编strlen()函数,并用它递归调用编写revers(S)函数,给字符串S倒序
- C++程序设计实验报告(二十七)---第二周任务一(自定义函数用递归思想,即不断调用,反向输出二进制)
- 函数的递归调用
- C语言程序设计 函数递归调用示例
- ASP递归调用:已知节点查找根节点的函数
- C语言实现:函数的递归调用
- 函数的递归调用与栈