Jump to content
xisto Community
sureshkmit

C Puzzles

Recommended Posts

Thanks for your interest in C programming. Here, you will find a list of interesting C programming questions/puzzles. C is the basic language for all who are in the computer science field. You can post new c questions and puzzles. Please try to avoid the duplicates.
I hope that this will be very interesting and meaningful for "C" programmers.

Lets us start with simple question.

----------------------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>  int main()  {		  int a=10;		  switch(a)		  {				  case '1':					  printf("ONE\n");					  break;				  case '2':					  printf("TWO\n");					  break;				  defa1ut:					  printf("NONE\n");		  }		  return 0;  }

If you expect "NONE" is the output, u are wrong. Wats the output & How?

Share this post


Link to post
Share on other sites
If you expect "NONE" is the output, u are wrong. Wats the output & How?C Puzzles

The O/p will be NONE only because a has been declared as 10 before  the loop begins.

And as such the value that would be used would be the one declared.

-reply by Anubhav Baweja

Share this post


Link to post
Share on other sites
If you expect "NONE" is the output, u are wrong. Wats the output & How?C Puzzles

the structure of switch case is:

switch(a)

{

case 1:printf("oneand");   //not case '1':printf("oneand");

}

-reply by rajender

 

Share this post


Link to post
Share on other sites

If you expect "NONE" is the output, u are wrong. Wats the output & How?

Did you really test your program example?Because the "defa1ut" syntax.
Isn't it a mistyping for "default" ?
In that case I would say that you are strongly faulty.
As a teacher, you have to test what you are teaching us. And if you give us a copy-pastable example, this example has to be correct.
If you are a noob, you should test your cases before posting them. :P
And if you were a skilled c developer, you should not do such obvious syntax errors. :P

Share this post


Link to post
Share on other sites
for loop in CC Puzzles

StartF=1Sum=0For(j=1;j<=5;j++){For(l=j;l>=1;l--){F=f*lSum=sum+(1/f)}}Output sumEnd

-reply by S.FREEDA

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.