函数 int func(int i ,int N);
其中i <= N,功能输出i递增到N再递减到i的整数,每行输出一个数。比如func(1,5)就是
1
2
3
4
5
4
3
2
1
要求:
1、只能有1个语句,即一个分号
2、不能使用do while until goto for if关键字,不能使用?:和逗号运算符
其中i <= N,功能输出i递增到N再递减到i的整数,每行输出一个数。比如func(1,5)就是
1
2
3
4
5
4
3
2
1
要求:
1、只能有1个语句,即一个分号
2、不能使用do while until goto for if关键字,不能使用?:和逗号运算符
3、唯一能使用的库函数为printf
// recursive_print.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void recursive_print(int i, int N)
{
if (i < N)
{
printf("%d\n", i);
recursive_print(i+1, N);
}
printf("%d\n", i);
return;
}
int recursive_print2(int i, int N)
{
return (((N-i) && (!printf("%d\n", i) || !recursive_print2(i+1, N))) || printf("%d\n", i));
}
int _tmain(int argc, _TCHAR* argv[])
{
recursive_print2(1, 5);
return 0;
}