Small Technical puzzles……?
Hi all,
Well this Is not any competition, we all do lot of programming work but most of the
Times some small things skips even by the good experience programmer.
And these small snippet do revel the true colors of the programming language..
Well following is one of its own kinds…..
Code:
void main()
{
if (X)
printf("Hello");
else
printf("World");
}
What must be the condition (X) in "if" so as to print "HelloWorld"?
Please do post if you have one .......
Regards,
x8086
Re: Small Technical puzzles……?
My guess is:
Code:
int main()
{
if (!printf("Hello"))
printf("Hello");
else
printf("World");
}
I cannot think of a way to execute both branches of conditional expression, so if only one of them can be executed, the resst has to printed during condition test.
Hob
Re: Small Technical puzzles……?
Does ANYBODY has the answer to this QUESTION, Please?? It's making me eager.............
Re: Small Technical puzzles……?
void main()
{int x=1;
start:if(x=1)
{printf("Hello");
x++;
goto start;
}
else
printf("World");
}
Re: Small Technical puzzles……?
Quote:
Originally Posted by
pratikamlani
void main()
{int x=1;
start:if(x=1)
{printf("Hello");
x++;
goto start;
}
else
printf("World");
}
Honestly, if you're really going to violate the rules (only replace the X) to this extent, then why not simply:
Code:
int main()
{
printf("HelloWorld");
}
:cool:
Despite the fact that the OP never confirmed it (in six years), Hobson's proposed solution does solve the puzzle without violating the rules.
BTW, double :thumbd: for using goto...
EDIT: BTW2, despite the rule violation, yours does not solve the puzzle. Actually, it's an infinite loop. I'll leave it up to you to find out why... :D
Re: Small Technical puzzles……?