can we print 1 to 100 without using any if conditions and loops in c&c++?
Conditon: main point is you must not use recursion...and doesnt hardcode code in it for e.g
print(1 2 3..etc);
C++ (
|
|
s/class/struct/;s/public://;s/static //;s/::/()./g saves 11 characters. – leftaroundabout Dec 30 '12 at 19:49 |
85C (gcc)
Assuming no command line arguments were passed. |
|||||
|
C
|
vignesh4303 disallowed "if conditions", not all conditionals, which is why I included both answers. – cardboard_box Jan 11 at 2:24 |
267this is the best I can think of, assuming using the preprocessor is fine.
|
||||
|
|
Ruby (11) [non-competitive]
(Thanks to histocrat) Previous 14-character solution:
This is a non-competitive answer (not C/C++ as requested) |
||||
Python 3 (25)
|
|||||||
|
Perl 6 (10)
If one wants to be able to read the numbers and therefore spaces between the numbers would be nice, the following will do the trick.
|
|||
|
|
C++ (115)
|
|||
|
|
Perl (65)Here's a non-trivial Perl approach (not like
The output is a list of all integers from 0 to 100 with newlines. |
||||
|
|
print "1 to 100"orprint 1 2 3 4 5 6 (etc)? – beary605 Dec 27 '12 at 7:19gotocount? – minitech Dec 31 '12 at 0:50