Look at a very interesting topic.
The topic is this:
Please print the number from 1 to 1000, but you cannot use any of the loop statements or conditional statements.
I was also blindfolded when I saw the problem.
The first thing to think about is the recursive implementation,
But how do you jump out of this loop?
I thought about it, someone gave a hint that can be used with to judge:
Look at the code first:
#include <stdio.h>int print (int num) {num && print (num-1);p rintf ("%d", num); return num;} int main () {int num = 1;print (+); return 0;}
When you see this code, the person you know about C should know what that means.
In the C language, the,&& of this logical condition is preceded by 1, after continuing to judge this condition.
So it's easy to look at it, put a recursive call in the second with the condition, and then use the rules to make it simple to call
There's actually an algorithm, but I'm not able to use it when I debug in VS2010:
This algorithm means that the use of the divisor in the program can not be 0 to jump out of the loop, the result is output, so this method is not possible.
Then there is another way to be interesting.
In fact, in this method of the first idea, very interesting people think I will play 1000 printf.
It's a way, but it's too clumsy.
In fact, macros are a powerful feature that you can use with macros.
#include <stdio.h> #define OUT (i) printf ("%d\n", i++), #define NEC (n) n n n n n. N n n n n n//10^n printf#define outt (i) n EC (NEC (Out (i))) int main () {int i = 1;outt (i); return 0;}
This macro replacement is very interesting, a few lines of code, representing the 1000 printf, haha
This article is from the "egg-left" blog, please be sure to keep this source http://memory73.blog.51cto.com/10530560/1682921
Print the number from 1 to 1000, but you cannot use any of the loop statements or conditional statements.