Oracle面试题-不用循环来打印1-1000 (zz)

这是一道Oracle面试题目,要求在不使用任何循环或条件语句的情况下,打印出从1到1000的数字。解决方案不应简单地重复打印语句1000次。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://topic.youkuaiyun.com/u/20121004/21/b81b41ff-31f0-453c-848b-6427cc3fd234.html

Oracle面试题

Task:
 Print numbers from 1 to 1000 without using any loop or conditional statements. Don't just write the printf() or cout statement 1000 times.

大家的答案总结:满分10分
1,19楼的12分:多加2分,因为很有创意,说明对c++理解的很清楚;
C/C++ code
        
#include < iostream > using namespace std; class print { public : print(){ num ++ ; cout << num << endl; } private : static int num; }; int print::num = 0 ; int main() { print * pt = new print[ 1000 ]; delete [] pt; pt = NULL; return 0 ; }

2,22楼的,10分,为标准答案;
C/C++ code
        
void print() { static int i = 1 ; (i - 1001 ) && (printf( " %d " , i ++ )) && (print(), 0 ); }

3,28楼的7分,找到了题目的bug,用#define解决;
C/C++ code
#include <stdio.h>
#define Out(i)       printf("%d\n", i++);
#define REP(N)       N N N N N N N N N N
#define Out1000(i)   REP(REP(REP(Out(i))));
void main()
{
 int i = 1;
 Out1000(i);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值