Previously published "6 Abnormal C language Hello World program" [Cool shell link] [csdn link], mainly is like everybody shows some C language of abnormal play. Also showed that the program can be written so that people do not understand, in that article, you can see a lot of people's message, a lot of people think it is fun, yes, it was used for friends "entertainment" for entertainment, the east, not too serious.
However, through this extreme writing, you can see that the source code can be written so complex and difficult to understand. Everyone may be laugh in admiration, and I hope that we can seriously think after the entertainment, you do not think we will not make the code so complicated, but not as extreme as the 6 Hello World, but, to tell the truth, Each of us has a clear program to make a mess of potential, but not the same level, I am not here to alarmist, everyone to take good of themselves.
The following is a step through step tutorial that teaches you how to make a clear code complex and difficult to understand. Of course, this is just a "concise tutorial". Or that sentence-"This article is for friends to" amuse themselves, if you want to feel interesting, the top sticker. If you don't think it's interesting, laugh. Just for fun, don't take it too seriously. ”
Normal procedure
Here is a program to find prime numbers:
void primes(int cap)
{
int i, j, composite;
for(i = 2; i < cap; ++i) {
composite = 0;
for(j = 2; j * j < i; ++j) {
composite += !(i % j);
}
if(!composite){
printf("%d\t", i);
}
}
}
int main()
{
primes(100);
}
Let's take a look at how to make this piece of code complex and difficult to understand.
First step, change for a while
In general, for the bad to follow is a bad one, the above program has a two for loop, we not only want to turn it into a while loop, but also to the double loop into a heavy loop, and then use a lot of if-else statements to judge.
void primes(int cap)
{
int i, j, composite, t = 0;
while(t < cap * cap) {
i = t / cap;
j = t++ % cap;
if(i <= 1);
else if(!j)
composite = j;
else if(j == i && !composite)
printf("%d\t",i);
else if(j > 1 && j < i)
composite += !(i % j);
}
}
int main()
{
primes(100);
}