Display 1 to 1000 in C ++ without using a semicolon

6

Make a program in C ++ that displays on the screen the numbers from 1 to 1000, relying on these two, but without using the semicolon .

I have already made a sketch here but I have to choose between 1 or 1000.

Complementing, my code:

#include <iostream>
int main(int x = 0) {

  while (x <= 1000 && std::cout << x++ << std::endl) {}
 }

Why does not it display the number 1 ? Guys, here, for example; link , the output is correct. Could anyone explain to me why g ++ display from 2 ?

    
asked by anonymous 18.05.2014 / 19:57

2 answers

5

If that's the goal, let's go:

76 bytes

#include <cstdio>
int main(int a,char**){while(printf("%d ",a++)&&a<1001){}}

But if it is already in C, we can leave it a bit smaller (ignoring the warnings, of course):

41 bytes

main(a){while(printf("%d ",a++)&&a<11){}}
    
18.05.2014 / 20:43
2

One possible solution:

#include <stdio.h>
#include <stdlib.h>

int main(int num=0,char**){
    if(printf("%d\t",++num) && (&main + (&exit - &main)*(num/1000))(num+1)){}
}

gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

    
20.05.2014 / 04:40