Solve the given C Puzzle

Status
Not open for further replies.
OP
A

adi007

Youngling
^^good ...
u and QM have solved the puzzle..both of u get points..
Try solving it without using even switch..:D..let's see who solves then..
 
K

khattam_

Guest
^^good ...
u and QM have solved the puzzle..both of u get points..
Try solving it without using even switch..:D..let's see who solves then..


here you go:

Code:
#include <stdio.h>
#include <conio.h>

int main (void){
printf("\nHello!\nContinue(y/n)");
(getche()=='y'&&printf("\b "))?main():printf("\b \nBye, Press any key to exit.")&&getche()&&printf("\b ");
}
 

vinit suri

Broken In
hey adi007 i hope u dont mind if i ask a small question here...der was no activity in d thread 4 quite sm time now so i thot ill post...

hey 1 small question from my side......its extremely simple..........
Write a program 2 print "yes i can print without ;"........
obviously ne1 can do it without restrictions...
restrictions:
1.only stdio.h 2 b used
2.no macros
3.program inside main() shd b only 1 line.
4.no user defined functions.
5.no semicolon to be used newhr in the entire program.


i know its extremely simple n all of u will get it very easily:D:D........
 
K

khattam_

Guest
hey adi007 i hope u dont mind if i ask a small question here...der was no activity in d thread 4 quite sm time now so i thot ill post...

hey 1 small question from my side......its extremely simple..........
Write a program 2 print "yes i can print without ;"........
obviously ne1 can do it without restrictions...
restrictions:
1.only stdio.h 2 b used
2.no macros
3.program inside main() shd b only 1 line.
4.no user defined functions.
5.no semicolon to be used newhr in the entire program.


i know its extremely simple n all of u will get it very easily:D:D........

Code:
#include <stdio.h>

void main(void)
{
if (printf ("yes i can print without %c",59)){}
}
 
OP
A

adi007

Youngling
I am currently busy..so i am unable to give new puzzles..till then anyone can ask puzzle..The thread is open for everyone but let there be only single unsolved puzzle at a single time..
 
K

khattam_

Guest
yes dats the right answer.....:p....but dat was 2 simple
i guess so.

Ok, here's one from my side. The program should output:
Code:
10
9
8
7
6
5
4
3
2
1

Without the rules, this shud be any C learners second program after Hello! World. So here they are:
1. One Variable.
2. Two lines including variable declaration.
3. No functions except main.
4. No if, switch or any conditional statement (Yes, don't even use ? : conditional statement)
5. No for, do, while or goto.
6. printf statement to print this directly won't make it a puzzle. So don't try that. Use printf to print one number at a time.
7. Don't try multiple statements with semicolons all in one line. Thats lame too.
8. No global declarations or macros.
9. Maximum 2 header files, stdio.h and conio.h

Not so easy. Lets see. I'll post the solution after 2 weeks, if noone is able to solve it.
 
Last edited by a moderator:

redhat

Mad and Furious
Can some1 please start such a thread for puzzles in Java??
Id like to solve them, since im good at Java, but not C...
 
K

khattam_

Guest
i guess so.

Ok, here's one from my side. The program should output:
Code:
10
9
8
7
6
5
4
3
2
1

Without the rules, this shud be any C learners second program after Hello! World. So here they are:
1. One Variable.
2. Two lines including variable declaration.
3. No functions except main.
4. No if, switch or any conditional statement (Yes, don't even use ? : conditional statement)
5. No for, do, while or goto.
6. printf statement to print this directly won't make it a puzzle. So don't try that. Use printf to print one number at a time.
7. Don't try multiple statements with semicolons all in one line. Thats lame too.
8. No global declarations or macros.
9. Maximum 2 header files, stdio.h and conio.h

Not so easy. Lets see. I'll post the solution after 2 weeks, if noone is able to solve it.



Since nobody solved it, here's the solution:
Code:
#include <stdio.h>

int main(void)
{
static int i=10;
return printf("%d\n",i--)&&i&&main();
}
 
K

khattam_

Guest
read as "&& i && main();"

He's recursively calling main() till 'i' becomes 0

exactly....

as it is "and" condition, so when i becomes 0, the condition is already false, so the main() need not be evaluated....
 
Status
Not open for further replies.
Top Bottom