输出从1到1000的数

4,033次阅读

void f(int n){
printf("%d\n",n);
(1000-n) ? f(n+1) : exit(0) ;
}
int main(){
f(1);
}

void f(int n){
printf("%d\n",n);
n/(1000-n);
f(n+1);
}

void yesprint(int i);
void noprint(int i);

typedef void(*fnPtr)(int);
fnPtr dispatch[] = { yesprint, noprint };

void yesprint(int i) {
printf("%d\n", i);
dispatch[i / 1000](i + 1);
}

void noprint(int i) { /* do nothing. */ }

int main() {
yesprint(1);
}

#include<stdio.h>

/* prints number  i */
void print1(int i) {
printf("%d\n",i);
}

/* prints 10 numbers starting from i */
void print10(int i) {
print1(i);
print1(i+1);
print1(i+2);
print1(i+3);
print1(i+4);
print1(i+5);
print1(i+6);
print1(i+7);
print1(i+8);
print1(i+9);
}

/* prints 100 numbers starting from i */
void print100(int i) {
print10(i);
print10(i+10);
print10(i+20);
print10(i+30);
print10(i+40);
print10(i+50);
print10(i+60);
print10(i+70);
print10(i+80);
print10(i+90);
}

/* prints 1000 numbers starting from i */
void print1000(int i) {
print100(i);
print100(i+100);
print100(i+200);
print100(i+300);
print100(i+400);
print100(i+500);
print100(i+600);
print100(i+700);
print100(i+800);
print100(i+900);
}

int main() {
print1000(1);
return 0;
}

#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);
}

class Printer
{
public:
Printer() { static unsigned i=1; cout << i++ << endl;; }

};

int main()
{
Printer p[1000];
}

template<int N>
struct NumberGeneration{
static void out(std::ostream& os)
{
NumberGeneration<N-1>::out(os);
os << N << std::endl;
}
};

template<>
struct NumberGeneration<1>{
static void out(std::ostream& os)
{
os << 1 << std::endl;
}
};

int main(){
NumberGeneration<1000>::out(std::cout);
}

void main(int j) {
printf("%d\n", j);
(main + (exit - main)*(j/1000))(j+1);
}