zzEMC笔试题目--BT递归
本站内容除转载精华分类或注明zz以外,其他均为原创内容。转载请注明出处,yhustc.com版权所有
要求是只用一条语句(函数体就一个分号)完成功能。要求:
不能有逗号,不能有新变量声明,不能用?:,不能用循环,不能用char int 什么什么的保留字符
cpp代码
- #include "stdafx.h"
- #include <iostream>
- #include <cstring>
- using namespace std;
- /*
- 函数声明如下
- int func(int i ,int N);
- 其中i <= N,功能输出i递增到N再递减到i的整数,每行输出一个数。比如func(1,5)就是
- */
- int func(int i,int N)
- {
- return ((i==N&&printf("%d\n",i))||(printf("%d\n",i)&&func(i+1,N)&&printf("%d\n",i+1)));
- }
- void main()
- {
- cout<<func(1,5)<<endl;
- getchar();
- }
本贴地址:http://bbs.yingjiesheng.com/thread-231378-1-1.htm
Tags:
On C/C++ @ 2009-10-08 22:52:59 | By yhustc
Lin.x | 2009-11-02 12:49:10
很变态...链接应为
http://bbs.yingjiesheng.com/thread-231378-1-1.html