输出从1到1000的数

    技术2025-02-07  24

    请把从1到1000的数打印出来,但你不能使用任何的循环语句或是条件语句。更不能写1000个printf或是cout。

    在奋斗乐园上看到这题,结合最近刚刚学的静态成员函数,看到了一种很妙的方法。

    class Printer { public: Printer() { static unsigned i=1; cout << i++ << endl;; } }; int main() { Printer p[1000]; }

    最新回复(0)