# Solve the given C Puzzle



## adi007 (Oct 15, 2007)

Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka

*farm3.static.flickr.com/2052/2086499468_1f153310e7_o.gif​
Currently you are witnessing C puzzle 12 


> The answer to this puzzle will be given soon till i frame another puzzle..





> _
> Don't forget to visit these other threads started by me
> 1.Lesser known facts in C:facts that you never knew about C
> 
> ...





> *Index*_
> 1.Puzzle 1[#2]
> 2.Puzzle 2[#14]
> 3.Puzzle 3[#25]
> ...


*
First,let me state the rules in this thread:
1.Please do not give suggestions or hints.Specify the modified program only.
2.Before posting the program make sure it's working in the way i want.
*

Here is the 12th C puzzle



write a c program which gives the output as below..


```
Hello!
Continue(y/n)
Hello!
Continue(y/n)
Bye,press any key to exit
```
^^When i press 'y' the program prints Hello! once more and if i press any other key the program ends 

If i didn't specify the rules then anyone can solve this 


> Rules*
> maximum of 2 header files -stdio.h and conio.h
> no variables,constants
> no structures,pointers,user defined functions..
> ...



Note :Specify your modified program along with the answer

Awards gallary:
Total puzzles solved :11
anuj919                     3
me (If no one gets the solution then points will be for me)                       2
saurabh kakkar          2
fun2sh                       2
eggman                     1
nigthtcrawler               1
a_k_s_h_a_y              1
anantkhaitan             1
khattam                     1
maddy354                   1

Leading:anuj919


----------



## casanova (Oct 15, 2007)

C Puzzle 1


> here is a simple c program
> 
> ```
> #include<stdio.h>
> ...



Edited:
To show the first puzzle as requested by Adi


----------



## aditya.shevade (Oct 15, 2007)

^^ Read man.... he says no use of anything other than scaf... why though?


----------



## eggman (Oct 15, 2007)

Well you can use *Edit Set [...]* instead of *%s* in the scanf function.....it'll solve the problem....


----------



## saurabh kakkar (Oct 15, 2007)

following Program will work 


```
#include<stdio.h>
void main()
{
char str[100];
printf("Enter any string\n");
scanf("%[^\n]s",str);         //<----- Imp step--------
printf("\n You entered string %s \n",str);
}
```


----------



## eggman (Oct 15, 2007)

aditya.shevade said:
			
		

> ^^ Read man.... he says no use of anything other than scaf... *why though?*


Thats the puzzle......


----------



## aditya.shevade (Oct 15, 2007)

^^ 

:-d


----------



## Sykora (Oct 15, 2007)

```
#include<stdio.h>
int main() {
    char str[100], c;
    int i = 0;
    printf("Enter any string\n");
    do {
        scanf("%c", &c);
        str[i++] = c;
    } while (c != '\n' && i < 99);
    str[i] = '\0'
    printf("\n You entered string %s \n",str);
    return 0;
}
```

EDIT : || changed to &&.


----------



## Yamaraj (Oct 15, 2007)

Sykora said:
			
		

> ```
> #include<stdio.h>
> 
> #define MAXLEN 100
> ...


There is a little logic error here. You should have used AND in stead of OR. And, use of magic numbers should be discouraged.


----------



## saurabh kakkar (Oct 15, 2007)

I have given the soultion already in post no 5 here it goes again


```
#include<stdio.h>
void main()
{
char str[100];
printf("Enter any string\n");
scanf("%[^\n]s",str);         //<----- Imp step--------
printf("\n You entered string %s \n",str);
}
```


----------



## The_Devil_Himself (Oct 15, 2007)

well done sykora,saurabh,and yamaraj.You are the chamions.


----------



## adi007 (Oct 16, 2007)

Sykora said:
			
		

> ```
> #include<stdio.h>
> int main() {
> char str[100], c;
> ...


^^ You have used new variables called 'c' 'i'. I told to modify the existing program.

So the winner is saurabh kakkar and eggman(Because he suggested the use of Edit set)



			
				eggman said:
			
		

> Well you can use *Edit Set [...]* instead of *%s* in the scanf function.....it'll solve the problem....


From next puzzle ,specify modified program also.


----------



## Projjwal (Oct 16, 2007)

i think saurabh kakkar is 100% correct.that's the right way to do it. 

@Sykora is also correct but do while make this simple problem complex & complexity also higher  than saurabh .

My vote goes to saurabh .


----------



## adi007 (Oct 18, 2007)

adi007 said:
			
		

> Here is the 2nd C Puzzle
> 
> Here is a simple C program
> 
> ...


New puzzle added.Thread updated.

No responses  I think either the puzzle is too difficult or i have not made some points clear


Not even one try
That's bad


----------



## saurabh kakkar (Oct 18, 2007)

adi007 said:
			
		

> Here is the 2nd C Puzzle
> 
> Here is a simple C program
> 
> ...


----------



## adi007 (Oct 19, 2007)

wrong mate.


```
1.The keyword if or operator '?' should come only once in a program
2.No logical operator's are allowed (that means && || ! should not be used)
3.No new variabels must be used
4.No header file other than the existing one should be used
```
Rules Updated


----------



## adi007 (Oct 22, 2007)

last day for the answers.Tommorow i will post solution.


----------



## fun2sh (Oct 22, 2007)

hey != is not a logical operator. its comparetion operator. 
and i hav made this program. will post it as soon i get my laptop. Abhi me admitted in hospital since 17th. 

i an just facin 1 problem in my program.for '27' OR any 2digit no, for first variable its tellin 'GOOD'


----------



## adi007 (Oct 22, 2007)

^^Sorry  typing mistake  it is '!' not '!=''.



			
				fun2sh said:
			
		

> i an just facin 1 problem in my program.for '27' OR any 2digit no, for first variable its tellin 'GOOD'


That's Ok.Because it depends upon the computer and the compiler.In my home i use linux and i have extracted the output from it.After trying this in TurboC++,i faced the same problem as you.Actually what's happening is it taking only a single character from 27 and assigning it to char a.The remaining '7' is assigned to int b and the next decimal number is assigned to int c.And the last number is discarded.
So,I have removed this output



			
				adi007 said:
			
		

> ```
> Output:
> Enter a character and 2 integer values
> 27 23 45.96
> ...


No need to satisfy this condition

I hope now everything is clear 

SorryI think i made a mess of this puzzle


----------



## fun2sh (Oct 22, 2007)

here is th solution thaen


```
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
float b,c;
clrscr();
printf("Enter a character and 2 integer values\n");
b=scanf("%c %f %f",&a,&b,&c);
if(b!=3)
printf("\n thats bad");
else
printf("\n thats good");
getch();

}
```


----------



## [xubz] (Oct 22, 2007)

Um. . 27 is a ASCII Code. 65 is for A, so if you do printf("%c", 65); it prints out 'A'.

Thats the reason why its taking 27 as a character.

*www.devlist.com/Default.aspx


----------



## adi007 (Oct 22, 2007)

no...., 
it is not taking 27 as a character. it is just taking 2 as char and assigning it to 'a'.Remaining 7 to variable 'b''.The other value to 'c'.The last decimal value is discarded.


----------



## fun2sh (Oct 22, 2007)

hey! where r my points???


----------



## puzzleslover (Oct 23, 2007)

hi all,

i found website that gives money for solving puzzles  , please help me in solving them    . the website is www.jadook.com

i know that you are very skilled puzzles solvers, plz help.


----------



## adi007 (Oct 23, 2007)

Here is the solution for puzzle2


```
#include<stdio.h>
#include<conio.h>
void main()
{
char a;
int b,c;
clrscr();
printf("Enter a character and 2 integer values\n");
if (scanf("%c %d %d",&a,&b,&c)==3)
printf("\n thats good");
else
printf("\n thats bad");
getch();
}
```

Find more info about this at my lesser known C facts thread *www.thinkdigit.com/forum/showthread.php?p=640073#post640073

the answer given by fun2sh is similar to it.So the point goes to fun2sh.



			
				adi007 said:
			
		

> Here is the 3rd C Puzzle
> 
> Here is a simple C program
> 
> ...


Puzzle 3 added.Thread updated


----------



## piyush gupta (Oct 23, 2007)

Enumerations are defined much like structures. An example definition is as follows:

    enum coin { ten_cent, quart_doll, half_doll, dollar };
An example declaration is:

    enum coin money;
Given this definition and declaration, the following statements are valid:

    money = quart_doll;

    if(money == quart_doll)
     printf("is 25 cents\n");
In an enumeration, each symbol stands for an integer value. For example, using the above definition and declaration:

    printf("%d %d", ten_cent, dollar);
displays 0 3 on the screen.



i thinks using them your puzzle can be solved easily...

i last worked on C in 2001 its long time and I cant write exact code here now...


----------



## adi007 (Oct 24, 2007)

^^ i want only program.
Please specify your modified program along with the answer.

no responses???


----------



## saurabh kakkar (Oct 24, 2007)

*EDIT: Problem solved*

Solution for 3rd C Puzzle

```
#include<stdio.h>
#include<conio.h>
void main()
{
enum days{
sunday=1,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
};
//THIS IS IMP STEP
days a,b,c,d,e,f,g;
a=sunday,
b=monday,
c=tuesday,
d=wednesday,
e=thursday,
f=friday,
g=saturday;

clrscr();
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",a,b,c,d,e,f,g);
getch();
}
```

*OR*

```
#include<stdio.h>
#include<conio.h>
void main()
{
enum days{
sunday=1,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
};
//THIS IS IMP STEP
days a=sunday,b=monday,c=tuesday,d=wednesday,e=thursday,f=friday,
g=saturday;

clrscr();
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",a,b,c,d,e,f,g);
getch();
}
```


----------



## piyush gupta (Oct 24, 2007)

adi007 said:
			
		

> ^^ i want only program.
> Please specify your modified program along with the answer.
> 
> no responses???


 
i thinks sourabh solved the puzzle...

hope u will giv eme some credit at least for the idea
whats next buddy


----------



## adi007 (Oct 25, 2007)

I program suggested by saurabh will give the output like this

```
0
1
2
3
4
5
6
```
make some modifications..


----------



## saurabh kakkar (Oct 25, 2007)

^^ sorry dude I made mistake in hurry  .here is the correct solution

```
#include<stdio.h>
#include<conio.h>
void main()
{
enum days{
sunday=1,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
};
//THIS IS IMP STEP
days a,b,c,d,e,f,g;
a=sunday,
b=monday,
c=tuesday,
d=wednesday,
e=thursday,
f=friday,
g=saturday;

clrscr();
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",a,b,c,d,e,f,g);
getch();
}
```

*OR*

```
#include<stdio.h>
#include<conio.h>
void main()
{
enum days{
sunday=1,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
};
//THIS IS IMP STEP
days a=sunday,b=monday,c=tuesday,d=wednesday,e=thursday,f=friday,
g=saturday;

clrscr();
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",a,b,c,d,e,f,g);
getch();
}
```


----------



## aditya.shevade (Oct 25, 2007)

^^ Correct.


----------



## ALIM (Oct 25, 2007)

you can use enum data type.
enum
{
sunday
monday
tuesday;
wednesday;
thursday;
friday;
saturday;
}weekdays

then you can decalre:
a,b,c,d,e,f,g of type weekdays

this will resolve the problem.



			
				adi007 said:
			
		

> Here is the 3rd C Puzzle
> 
> Here is a simple C program
> 
> ...


----------



## adi007 (Oct 26, 2007)

Here is the solution for 3rd C Puzzle

```
#include<stdio.h>
#include<conio.h>
void main()
{
enum days{
sunday=1,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
};
enum days a,b,c,d,e,f,g;
a=sunday,
b=monday,
c=tuesday,
d=wednesday,
e=thursday,
f=friday,
g=saturday;

clrscr();
printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n",a,b,c,d,e,f,g);
getch();
}
```

puzzle solved by saurabh kakkar.But i just think that you have to specify 'enum days' instead of simply days.
Did you executed the program saurabh...
Also a round of applause to *piyush gupta* who first suggested the use of enum.I just hope that from next puzzle onwards he will suggest the program also.


----------



## saurabh kakkar (Oct 27, 2007)

> i just think that you have to specify 'enum days' instead of simply days.


No buddy there is no need to spectify 'enum days'  



> Did you executed the program saurabh...



Yes, before posting any c++ program I make sure to compile the program but since I use TurboC++ compiler so i can not paste the output


----------



## adi007 (Oct 29, 2007)

adi007 said:
			
		

> *
> 
> 
> 
> ...


* 
Puzzle 4 added.Thread Updated!!.
I had to write this twice because after writing once i clicked save and it asked my password and username,I specifed it but it just got discarded

Please rate this thread!!*


----------



## nightcrawler (Nov 3, 2007)

adi007 said:
			
		

> Puzzle 4 added.Thread Updated!!.
> I had to write this twice because after writing once i clicked save and it asked my password and username,I specifed it but it just got discarded
> 
> Please rate this thread!!



Since no one has answered the question I will give my try. I hope it is correct

the question is


```
The question

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
            long double pi=3.14159265,a,r;
            int pre;
            clrscr();
            printf("Enter precision of pi between 0 and 8\n");
            scanf("%d",&pre);
            printf("Enter radius\n");
            scanf("%Lf",&r);
            /*Complete the program*/
            getch();
}
```


```
Output
Enter precision of pi between 0 and 8
3
Enter radius
25.3
The value of pi taken=3.141 and the area of the circle is 2010.522690
```
The Possible Answer

```
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
            long double pi=3.14159265,a,r;
            int pre;
            clrscr();
            printf("Enter precision of pi between 0 and 8\n");
            scanf("%d",&pre);
            printf("Enter radius\n");
            scanf("%Lf",&r);
            pi = floor(pi *pow(10, pre) + 0.5) / pow(10, pre);  // this will set the precision according to input value
            a = pi * r * r;
            printf("The Value of pi taken is %.*1$Lf and the area of the circle is %Lf\n", pre, pi, a); /* .*1$ will take the precision value after the decimal from the first argument of the printf which should be an int which is pre */
            getch();
}
```
*EDIT:  *Made changes to the code. Complies with the requirement now I think.


----------



## adi007 (Nov 5, 2007)

to nightcrawler :
I just said to complete the statements after.That means you are  not allowed to edit or add any statements before.

And secondly,you have used '?' operator which i said you shouldn't

```
/**precision > 8[B]?[/B] *precision=8:(*precision < 0? *precision=0:;);*/  /* Commented because of if not allowed rule function call useless*/
```



> 1.If and it's variants,switch,?,for,while,do..while,goto -->not allowed



If anyone wants to try, try today itself because I will give the answer tommorow.


----------



## nightcrawler (Nov 5, 2007)

Hey I have commented it. So it is not being used if you look closely. Anyways I will remove that part all together.


----------



## adi007 (Nov 5, 2007)

^^ please rewrite the program in other post along with the output's and please no comments

*nightcrawl attention please:*
I have compiled your c program and the following is the output of your c program:


```
Enter precision of pi between 0 and 8
6
Enter radius
25.3
The Value of pi taken is 3.141593 and the area of the circle is 2010.902263
```

But i have stated that


> pre - radius - pi value taken - Area
> 0 - 25.3 - 3 - 1920.270000
> 1 - 25.3 - 3.1 - 1984.279000
> 2 - 25.3 - 3.14 - 2009.882600
> ...



so your output should be like this


```
Enter precision of pi between 0 and 8
6
Enter radius
25.3
The Value of pi taken is 3.141592 and the area of the circle is 2010.901623
```

means no round off should takes place

Your c program is making roundoff for 4,6,7 values of precesion


----------



## nightcrawler (Nov 5, 2007)

Ok. I forgot that part as well. Anyways writing the code again wherin I don't round of the value of the number in floor call. Also made changes to printf statement. The program is running as expected on a Linux box minus getch, clrscr calls and conio.h header files and plus the int return format of main. The change to printf statement was to correct the absurd behaviour in linux box wherin the output was not being printed properly. I think this printf should also work in tc/devc++ or any other win32 C compiler


```
#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
    long double pi=3.14159265,a,r;
    int pre;
    clrscr();
    printf("Enter precision of pi between 0 and 8\n");
    scanf("%d",&pre);
    printf("Enter radius\n");
    scanf("%Lf",&r);
    pi = floor(pi *pow(10, pre)) / pow(10, pre);  // this will set the precision according to input value
    a = pi * r * r;
    printf("The Value of pi taken is %1.*3$Lf and the area of the circle is %Lf\n", pre, pi, a); 
    getch();
}
```
The Output

```
Enter precision of pi between 0 and 8
6
Enter radius
25.3
The Value of pi taken is 3.141592 and the area of the circle is 2010.901623

Enter precision of pi between 0 and 8
4
Enter radius
25.3
The Value of pi taken is 3.1415 and the area of the circle is 2010.842735

Enter precision of pi between 0 and 8
7
Enter radius
25.3
The Value of pi taken is 3.1415926 and the area of the circle is 2010.902007
```
I think you will find this correct


----------



## adi007 (Nov 6, 2007)

nightcrawler has solved the puzzle.This was a tough puzzle.I thought that i will get the point myself but it didn't happen.
Anyways,a round of applause to nightcrawler 
Linux version of this program is

```
#include<stdio.h>
#include<math.h>                                                                     
main()
{
    long double pi=3.14159265,a,r;
    int pre;
    printf("Enter precision of pi between 0 and 8\n");
    scanf("%d",&pre);
    printf("Enter radius\n");
    scanf("%Lf",&r);
    pi = floor(pi *pow(10, pre)) / pow(10, pre);
    a = pi * r * r;
    printf("The Value of pi taken is %.*Lf and the area of the circle is %Lf\n", pre, pi, a);
}
```

Note:
The compilation of this program will sometimes lead to an error
Then you have to compile this program  by suffixing -lm at end of cc command
i.e,

```
cc adi.c -lm
```
assuming that adi.c is the filename

_find more about *floor* function at my Lesser Known Facts in C thread
*www.thinkdigit.com/forum/showpost.php?p=652953#post652953_




> *
> But there is another method to solve this puzzle without using floor function.So if there is someone other than nightcrawler who know this, then post it here within tommorow.1 point will be given to that person also.
> The other answer will be given tommorow.
> *



Another method to solve the puzzle without using floor function


```
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    long double pi=3.14159265,a,r;
    int pre;
    clrscr();
    printf("Enter precision of pi between 0 and 8\n");
    scanf("%d",&pre);
    printf("Enter radius\n");
    scanf("%Lf",&r);
    pi=(long)(pi*pow(10, pre));
    pi=pi/pow(10, pre);
    a = pi * r * r;
    printf("The Value of pi taken is %.*Lf and the area of the circle is %Lf\n", pre, pi, a); 
    getch();
}
```


_


		Code:
	

printf("The Value of pi taken is %.*Lf and the area of the circle is %Lf\n", pre, pi, a);

^^
More info about this statement at my Lesser known facts in C thread
*www.thinkdigit.com/forum/showthread.php?p=652971#post652971
_



			
				adi007 said:
			
		

> *
> First,let me state the rules in this thread:
> 1.Please do not give suggestions or hints.Specify the modified program only.
> 2.Before posting the program make sure it's working in the way i wan.
> ...


Puzzle 5 added! Thread updated


----------



## saurabh kakkar (Nov 6, 2007)

Puzzle 5 Solved 

```
#include<stdio.h>
#include<conio.h>
void main()
{
long signed int a,b;
clrscr();
puts("enter the value for a");
(fscanf(stdin, "%ld", &a));
puts("enter the value for b");
(fscanf(stdin, "%ld", &b));
printf("%ld" "+" "%ld" "=" "%ld"" and ""%ld" "-" "%ld" "=" "%ld",a,b,a+b,a,b,a-b);
getch();
}
```

*I can not provide the output as I m using Turbo C++ compiler *


----------



## adi007 (Nov 7, 2007)

^^No saurab.Glance the rules carefully.


> *4.the symbol '&' shouldn't come in the program*


where as you have used it twice

```
(fscanf(stdin, "%ld", [B]&[/B]a));
(fscanf(stdin, "%ld", [B]&[/B]b));
```


----------



## adi007 (Nov 9, 2007)

No other try yet??

By the way,how C compiler decides Garbage value in case of dataoverflow
Find this out in my lesser known facts in c thread.
*www.thinkdigit.com/forum/showthread.php?p=655539#post655539


----------



## nightcrawler (Nov 9, 2007)

I will give it a try if no one knows...but saurabh_kakkar has almost figured it out i think.


----------



## adi007 (Nov 9, 2007)

^^will that means that you know the answer.If so,please do give the answer.





			
				saurabh kakkar said:
			
		

> *I can not provide the output as I m using Turbo C++ compiler *


_
How to save the output to a text file in TC++,find this out in my lesser known facts in c thread
*www.thinkdigit.com/forum/showthread.php?goto=lastpost&t=71047
_


----------



## adi007 (Nov 12, 2007)

Last day to solve the Puzzle.I will give answer tommorow.
Look's like i am going to get my first point


----------



## adi007 (Nov 13, 2007)

Answer to puzzle5.It's really surprise that no one was able to solve this puzzle which was there for a week.
The program hint is given by the rule that no & must be used.That means we have to use string.And use a function to convert the value stored by the string into int or long type....
Here is the program.......


```
#include<stdio.h>
#include<stdlib.h>
void main()
{
char a[10],b[10];
puts("Enter the value of a");
gets(a);
puts("Enter the value of b");
gets(b);
printf("%s+%s=%ld and %s-%s=%ld",a,b,(atol(a)+atol(b)),a,b,(atol(a)-atol(b)));
getch();
}
```

I have opened my account 

what is atol()???
find this out at my lesser known facts in C thread
*www.thinkdigit.com/forum/showthread.php?goto=lastpost&t=71047



			
				adi007 said:
			
		

> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> Currently you are witnessing C puzzle 6
> 
> ...



Puzzle 6 added!!Thread updated!!


----------



## fun2sh (Nov 13, 2007)

thats real EASY

HERE ITS IS 


```
#include<conio.h>
#include<stdio.h>
void main()
{clrscr();
char *s;
int i;
printf("%c enter the string :",10);
gets(s);
printf("Start %c%c",10,10);
for(i=0;*(s+i)!=NULL;i++)
{printf("%c%c",*(s+i),10);
}
printf("%cEnd",10);
getch();
}
```

HAHAHAHAHAHA!!!!!!!!!!!!!


----------



## saurabh kakkar (Nov 14, 2007)

Puzzle 6 solved 

```
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char *a;
printf("enter a string %c",10); // [b]ascii value of '\n' is 10[/b]
gets(a);
printf("%cStart%c",10,10);
for(;*a!='\0';a++)
{
printf("%c%c",*a,10);
}
printf("%cEnd",10);
getch();
}
```

* I have solved this puzzle only with single variable *


----------



## adi007 (Nov 15, 2007)

Ok ...
I am very very sorry that i asked such a simple puzzle  .fun2sh solved it on that day itself.The main problem while giving puzzles is u will not know whether the puzzle u asked is easy or not . Whether the fact u know are known by others or not.Normally ,i will ask my freinds the puzzle and if there are unable to answer then only i post the puzzle.

fun2sh has solved the puzzle.One point for him.

saurabh kakkar has given other possibility that could solve the puzzle by using only one variable.A big applause to him.Unfortunately, i couldn't give point to him since he answered lately.

New puzzle tommorow.I just hope that the puzzle is of high standard.....


----------



## Pathik (Nov 15, 2007)

Great thread @ Adi


----------



## adi007 (Nov 15, 2007)

^^thanks


----------



## fun2sh (Nov 15, 2007)

yeah ur puzzle was toooooo simple this time. a child play i say. but U R DOIN A GREAT JOB BUDDY.


----------



## saurabh kakkar (Nov 15, 2007)

> ...
> Unfortunately, i couldn't give point to him since he answered lately.



Dude this is not done U should award me also cos I did'nt knew at that time that puzzle 6 has been put 

and from next time onwards plz mention the date nd Time at which u will post new puzzle 

by the way I m very busy with my studies so May be i will not be able to participate 

regards 
saurabh kakkar


----------



## adi007 (Nov 16, 2007)

saurabh kakkar said:
			
		

> Dude this is not done U should award me also cos I did'nt knew at that time that puzzle 6 has been put


sorry
But i am helpless



			
				saurabh kakkar said:
			
		

> and from next time onwards plz mention the date nd Time at which u will post new puzzle


^^I will implement this


			
				saurabh kakkar said:
			
		

> by the way I m very busy with my studies so May be i will not be able to participate


That really sad

puzzle 7 Schedule
Date:Nov16 
Time:12:15 PM
Venue:this same thread



			
				adi007 said:
			
		

> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> Currently you are witnessing C puzzle 7
> 
> ...


puzzle 7 added!!.Thread updated


----------



## fun2sh (Nov 16, 2007)

is that really possible?


----------



## QwertyManiac (Nov 16, 2007)

Only 1 variable but constants are allowed as desired?


----------



## fun2sh (Nov 16, 2007)

wat do u mean by 


			
				adi007 said:
			
		

> No pointers,functions,structures,unions......


then how will one store a string (as arrays are also pointers)
n which functions r not allowed??????????


----------



## QwertyManiac (Nov 16, 2007)

He meant creating just strings using arrays and one's not allowed to create a sub-routine to process things.


----------



## fun2sh (Nov 16, 2007)

wat do u mean by 


			
				adi007 said:
			
		

> No pointers,functions,structures,unions......


then how will one store a string (as arrays are also pointers)
n which functions r not allowed??????????


----------



## adi007 (Nov 17, 2007)

QwertyManiac said:
			
		

> Only 1 variable but constants are allowed as desired?


no constants...



			
				fun2sh said:
			
		

> wat do u mean by
> 
> then how will one store a string (as arrays are also pointers)
> n which functions r not allowed??????????


arrays are not pointers..
There are the separate group of structured datatype..


----------



## fun2sh (Nov 19, 2007)

yeah they r seperate group of data structures but they too are based on pointers, so tel me can we use them or not.??


----------



## adi007 (Nov 22, 2007)

u can use arrays.....
make sure there is no * in the whole program....



			
				fun2sh said:
			
		

> n which functions r not allowed??????????


user defined functions are not allowed....
u must make sure that there is only one header file <stdio.h>


Hurry......
time is running...
Answer will be given on NOV 23


Last day to answer the puzzle...
Will give answer tommorow....
Looks like i will get the point


----------



## fun2sh (Nov 22, 2007)

can we use this statement 


```
char *string;
```

oh didnt read properly. cant use that statement 

oh didnt read properly. cant use that statement


----------



## adi007 (Nov 23, 2007)

> answer will given on next tuesday
> 
> (i have internals for the next 3 days  and the answer program needs a lot of explanation).So,Three days extra time


EDIT:Answer in #69.Explanation and logic on next tuesday(Nov27).....


----------



## fun2sh (Nov 23, 2007)

@offtopic
HEY ADI also MINE 3rd INTERNAL R GOIN ON!!!
but me is givin only unix exam coz i got avg of (24-25)/25 in rest subject. i didnt study for unix in 2nd internal coz of illness


@ontopic

can we use global variable and this operator *::*


----------



## adi007 (Nov 23, 2007)

Answer to puzzle 7

```
#include<stdio.h>
main()
{
char a[1000];
printf("Enter the string\n");
gets(a);
printf("Enter the character whose frequency is to be determined\n");
scanf("%c",&a[997]);
a[998]='0';a[999]='0';a[1000]='0';
for(;a[(a[998]-48)]!='\0';a[998]++)
 {
       if(a[997]==a[(a[998]-48)])
            a[1000]++;
 }
a[998]--;
for(;a[(a[999]-48)]!='\0';a[999]++)
 {
   if (a[(a[999]-48)]!=a[(a[998]-48)])
        {
        printf("\n%s is not a palindrome\n",a);
        break;
        }
   a[998]--;
 }
if(a[(a[999]-48)]=='\0')
      printf("\n%s is a palindrome\n",a);
for(a[998]='0';a[(a[998]-48)];a[998]++);
printf("The string \"%s\" contains %d characters and '%c' occurs %d times\n",a,a[998]-48,a[997],(a[1000]-48));
}
```

confused ??:
Don't worry.All explanation will be given on next tuesday....



			
				fun2sh said:
			
		

> @offtopic
> HEY ADI also MINE 3rd INTERNAL R GOIN ON!!!
> but me is givin only unix exam coz i got avg of (24-25)/25 in rest subject. i didnt study for unix in 2nd internal coz of illness


@offtopic
We have only 2 internals and the marks are added without reduction.Internals is for 20 marks.So 20+20+5(assignments)+5 (teachers wish)=50.The final exam will be condected  for 100 marks and will be reduced to 50.
Sick.isn't it 



			
				fun2sh said:
			
		

> @ontopic
> can we use global variable and this operator *::*


Sorry i didn't read this post .I just typed the program and tested and posted it without refreshing the thread....


----------



## fun2sh (Nov 23, 2007)

wel i was also doin this but usin a global variable, coz global variable is different from local 1. so i can use same name for both hence only one variable name is required.
but wat if i give a string greater than 1000 chars???
se usin global variable this wont be a problem as we can use locale to store the string while global to do the things u hav done.


----------



## adi007 (Nov 23, 2007)

I think 1000 is far more than sufficent for a string.....
If u declare a global and local variable with the same name then preference will be given to local variable.....
SO HOW CAN U USE BOTH OF THEM IF THEY ARE OF SAME NAME???


----------



## fun2sh (Nov 23, 2007)

that wat i was askin!!!

u can use a global variable usin :: operator

forexample 'a' is a global variable n local to
so 
'a' will mean local
while
::a wil mean global


----------



## adi007 (Nov 27, 2007)

good info fun2sh..Didn't knew this 
please post it in the lesser known facts in c thread ....



			
				adi007 said:
			
		

> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> Currently you are witnessing C puzzle 8
> 
> ...


puzzle 8 added!Thread updated


----------



## fun2sh (Nov 27, 2007)

wat do mean by "until a smiley is encountered" ??


----------



## QwertyManiac (Nov 27, 2007)

Until [noparse][/noparse] is typed in.


----------



## Faun (Nov 28, 2007)

its easy man, may be if i'll get time will post here

Common interview question.

Btw am not a C fanatic


----------



## adi007 (Nov 28, 2007)

QwertyManiac said:
			
		

> Until [noparse][/noparse] is typed in.


no...
smiley means smiley[] not [noparse] this -->[/noparse]
read this *www.thinkdigit.com/forum/showpost.php?p=654017&postcount=21



			
				T159 said:
			
		

> its easy man, may be if i'll get time will post here
> 
> Common interview question.
> 
> Btw am not a C fanatic


Believe me it's not so easy...


----------



## Faun (Nov 28, 2007)

adi007 said:
			
		

> no...
> smiley means smiley[] not [noparse] this -->[/noparse]
> read this *www.thinkdigit.com/forum/showpost.php?p=654017&postcount=21
> 
> ...


I hav done revesing the string.

Clarify some points:

Will there be upper bound to the length of the string ? or link list will be used ?
And that smiley thing will be ASCII code or a real jpeg file ?

I really dont like C , here is the bad code, someone can refine it further (I hav forgotten a lots of things in C):



> #include<stdio.h>
> #include<stdlib.h>
> 
> int recReverse( char *tempStrPtr )
> ...



The Output, with stack overflow:



> jit@jit-desktop:~$ ./a.out
> i love c and i think  it rocks
> *** stack smashing detected ***: ./a.out terminated
> i evol c dna i kniht  ti skcorAborted (core dumped)


The Bad:
1) This thing will overflow like hell
2) gets() is a dangerous escape
3) No smiley return


to be more explainable

 Code:
Enter the string
i luv_​ 
 as soon i press space,it will become // you hav already pressed spacwe before, how will the program know that this space is the end

 Code:
Enter the string
i vul _​


----------



## adi007 (Nov 28, 2007)

1.This program cannot be solved in Linux.Because u will not get a smiley in linux.You will get the smiley in TC.
2.There is no seperate input and output.The program is dynamic.



			
				T159 said:
			
		

> to be more explainable
> 
> Code:
> Enter the string
> ...


^^underscore represents the cursor position



			
				T159 said:
			
		

> I hav done revesing the string.
> 
> Clarify some points:
> And that smiley thing will be ASCII code or a real jpeg file ?


use CTRL B in TC editor and u will see yourself....



			
				T159 said:
			
		

> Will there be upper bound to the length of the string ?


^^yes


----------



## fun2sh (Nov 30, 2007)

hey can u give more examples of output involvin smiley. i m not gettin wat u want to do with smiley.


----------



## adi007 (Nov 30, 2007)

smiley is just the way to indicate the end....
It's just like normal char...


----------



## Faun (Nov 30, 2007)

adi007 said:
			
		

> smiley is just the way to indicate the end....
> It's just like normal char...



how do u enter smiley after string in cmd prompt ?

Hitting CTRL+B gives ^B


----------



## adi007 (Nov 30, 2007)

example program here
*www.thinkdigit.com/forum/showpost.php?p=654017&postcount=21


----------



## fun2sh (Nov 30, 2007)

wat if the smiley appears in th mid like this


> i luv digit forum  but i hate spamer



do u expect output like


> i vul tigid murof


----------



## Faun (Nov 30, 2007)

adi007 said:
			
		

> example program here
> *www.thinkdigit.com/forum/showpost.php?p=654017&postcount=21


yeah seen that.

During runtime also you have to press CTRL B to enter smiley

CTRL B gives ^B not a smiley in dos prompt


----------



## adi007 (Nov 30, 2007)

fun2sh said:
			
		

> wat if the smiley appears in th mid like this
> 
> 
> do u expect output like


noooo....
As soon as the smiley encounters the *program should end* by displaying 

```
Have a nice day
```
and the main thing is 
There is no separate output and input.The program is dynamic



			
				T159 said:
			
		

> yeah seen that.
> 
> During runtime also you have to press CTRL B to enter smiley
> 
> CTRL B gives ^B not a smiley in dos prompt


I am planning to upload the runtime vedio of the program on monday or tuesday...


----------



## Faun (Nov 30, 2007)

adi007 said:
			
		

> There is no separate output and input.The program is dynamic
> 
> 
> I am planning to upload the runtime vedio of the program on monday or tuesday...



that means that the input and output will be on same line

It would be nice if u can provide screenshot


----------



## adi007 (Dec 1, 2007)

i will post the gif file or link to runtime vedio on Tuseday(@offtopic :I am going to release my software *presenmaker(beta)* on that day....)
Date for the puzzle 8 has been extended till next Thursday...


----------



## anuj919 (Dec 1, 2007)

Hey I am also a student in 1st year in Gujarat & new in this puzzle

I have done puzzle 8

Here is the Solution...



*#include<stdio.h>
#include<conio.h>

//Function to return the reverse the string given as argument

char *str_rev(char str[100])
{
         char rev[100];
         int i,j;
              for(i=0;str!='\0';i++);
              i--;
              for(j=0;i>=0;i--)
              {
                           rev[j++]=str;
              }
              rev[j]='\0';
              return rev;
}


void main()
{
              char a[100][100],c;      // a is two dimentional array to store diffrent strings
                // c is temp variable

              int i=0,j=0,k=0;      // i is for i th string entered
                                                        // j is for j th letter of i th string

              clrscr();
              printf("Enter String \n");
              while((c=getche())!='')*_*         //=Ctrl+B*
*               {
                  if(c!=' ')
                  {
                               a[j++]=c;    **//If space is not entered put char at the end of i th word (i.e,a)
                  }
                  else
                  {
                               a[j]='\0';    **//If space is entered put null character at the end of i th word
                               i++;j=0;k=0;    **// increment no of words & make j=0 for next use

            //Now first clear the screen & start printing all the strings reversed

                               clrscr();    
                               printf("Enter String \n");
                               while(k<i)
                               {
                                            printf("%s ",str_rev(a[k]));
                                            k++;
                               }
                  }
              }

    //After smily print string in new line

              printf("\nHave a Nice Day");
              getch();
}
* 

_


----------



## Faun (Dec 1, 2007)

yeah thats correct   It was puzzle no 7.


----------



## anuj919 (Dec 2, 2007)

T159 said:
			
		

> yeah thats correct   It was puzzle no 7.




Sorry but it was puzzle no. 8


----------



## Faun (Dec 2, 2007)

anuj919 said:
			
		

> Sorry but it was puzzle no. 8


yeah my bad


----------



## adi007 (Dec 3, 2007)

i think the answer given by anuj919 is wrong....
Not yet compiled and checked ...
But i think what the program is doing is accept the string and then clear the screen and then print the reverse of the string.This is wrong because I said the program is dynamic.....
Anyways ,I have prepared the animated gif run time output,will post it tommorow......


----------



## Faun (Dec 3, 2007)

adi007 said:
			
		

> i think the answer given by anuj919 is wrong....
> Not yet compiled and checked ...
> But i think what the program is doing is accept the string and then clear the screen and then print the reverse of the string.This is wrong because I said the program is dynamic.....
> Anyways ,I have prepared the animated gif run time output,will post it tommorow......



no its reversing the word as soon as u press space, its dynamic.

I dunno wat else can be dynamic other than that ?


----------



## fun2sh (Dec 5, 2007)

yeah its dynamic..me to checked it n its reverses the strin as soon as u press a space bar


----------



## adi007 (Dec 5, 2007)

program compiled and checked ..
it works..
1 point to anuj919


----------



## adi007 (Dec 6, 2007)

adi007 said:
			
		

> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> *farm3.static.flickr.com/2052/2086499468_1f153310e7_o.gif​
> Currently you are witnessing C puzzle 9
> ...


puzzle 9 added thread updated!!


----------



## fun2sh (Dec 6, 2007)

are bhai why u givin same program now!!!!

waise now one question can we use strtok() function n gotoxy() function???


----------



## adi007 (Dec 6, 2007)

^^no


----------



## anuj919 (Dec 9, 2007)

I think it is next to impossible to solve the puzzle 9 without using getch/getche (Which r in "conio.h ") because without it one can't read sentence 'word by word'

So please can we use getch/getche?


----------



## adi007 (Dec 10, 2007)

anuj919 said:
			
		

> I think it is next to impossible to solve the puzzle 9 without using getch/getche (Which r in "conio.h ") because without it one can't read sentence 'word by word'
> 
> So please can we use getch/getche?


what....
getch() and getche() comes under stdio.h 
wait let me confirm it.....


----------



## QwertyManiac (Dec 10, 2007)

Under Turbo stuff, getch() comes in* conio.h*


----------



## adi007 (Dec 10, 2007)

confirmed...
getche() and getch() comes under stdio.h(tested in TC++ 3.0)..


----------



## Yamaraj (Dec 10, 2007)

adi007 said:
			
		

> confirmed...
> getche() and getch() comes under stdio.h(tested in TC++ 3.0)..


If you cannot tell ANSI/ISO standard C from a system-dependent implementation (i.e., Turbo C++), you ought to invest more time in learning the language rather than posting non-standard, useless, and tricky puzzles here.


----------



## fun2sh (Dec 10, 2007)

adi007 said:
			
		

> confirmed...
> getche() and getch() comes under stdio.h(tested in TC++ 3.0)..


no adi. it cant be!:shocked: i checked it again now n its comes in conio.h only!!n i hav the same tc as urs. even in the help file of tc its mentioned conio.h!!


----------



## adi007 (Dec 10, 2007)

hmmm..
i created the solution program by using conio.h for clrscr()
then i removed clrscr() and #include<conio.h>
then i made some modifications to the solution program and compiled it...
It worked fine..
I tested the program by using both getch() and getche() without using conio.h and it worked....
wait ..
I will confirm it later by creating the program from the scratch......


----------



## Yamaraj (Dec 10, 2007)

What is there to confirm? You should not have skipped studying the C Standard Library while you were busy mastering the syntax.

Non-standard and system/implementation dependent functions like getch(), getche() or clrscr() CANNOT reside in a standard header like stdio.h.


----------



## anuj919 (Dec 10, 2007)

So what have come out all your discussion 
Can we use getch/getche or not?


----------



## adi007 (Dec 11, 2007)

I accept my fault....
I am extermely sorry for the mistake...
I referred the help documentation and some books and found that getch() ,getche() comes under conio.h...
So rules are modified 
One can use getch(),getche() but must not use clrscr()
here are the modified rules



> Rules
> 1.No user defined functions..
> 2.*No usage of clrscr()*
> 3.No header file other than stdio.h and conio.h should be used.
> 4.No * symbol in the whole program



Now i let me explain why i commited such a big mistake..

I am using TC++ 3.0 for the past 3 years and have never used conio.h for getch() and getche().So i thought these 2 comes under stdio.h
The  following program works fine in my TC


```
#include<stdio.h>
void main()
{
clrscr();
printf("Press any key\n");
getche();
getch();
}
```

and even this works fine

```
void main()
{
clrscr();
printf("Press any key\n");
getche();
getch();
}
```

I have made the vedio file and will upload and give the link within this week...


----------



## fun2sh (Dec 11, 2007)

^^^strange???

has some settings been change of ur TC++ compiler??


----------



## QwertyManiac (Dec 11, 2007)

Yeah how does *stdio.h* cover *clrscr* as your code example claims so? Use standard code mate, and allow a wider population to join.


----------



## anuj919 (Dec 11, 2007)

*I got the answer again    


But yes Adithya is true , the program works fine without including "conio.h"
& can anyone tell me that how this happens in Turbo C++ 3.0   

Here is the answer:*


```
#include<stdio.h>
#include<conio.h>

void main()
{
	char b[999];
	int i=0,j=0;
	char c;

	printf("Enter the String\n");
	while((c=getche())!='')
	{
		if(c==' ')
		{
			for(j=0;j<=i;j++)
				printf("\b");
			for(j=i-1;j>=0;j--)
				printf("%c",b[j]);
			printf(" ");
			i=0;
		}
		else
			b[i++]=c;
	}
	printf("\nHave a Nice Day!");
	getch();
}
```


----------



## adi007 (Dec 12, 2007)

^^Very good 
puzzle 9 solved



			
				anuj919 said:
			
		

> But yes Adithya is true , the program works fine without including "conio.h"
> & can anyone tell me that how this happens in Turbo C++ 3.0


^^I had told this already but nobody believed me 
Thanks for supporting me...
New puzzle tommorow at 12:15 PM



			
				fun2sh said:
			
		

> has some settings been change of ur TC++ compiler??


^^nope..



			
				QwertyManiac said:
			
		

> Yeah how does *stdio.h* cover *clrscr* as your code example claims so? Use standard code mate, and allow a wider population to join.


^^ i will be careful from now on...


----------



## Yamaraj (Dec 12, 2007)

anuj919 said:
			
		

> *But yes Adithya is true , the program works fine without including "conio.h"
> & can anyone tell me that how this happens in Turbo C++ 3.0   *


*



			
				adi007 said:
			
		


			^^I had told this already but nobody believed me 
Thanks for supporting me...

Click to expand...

I wonder if it's of any use talking sense into people these days. Turbo C++ is NOT C or even C++. Either ask mods to change the title from "C puzzle" to "Turbo C++ puzzles", or spend some time reading the standard ANSI/ISO C and post accordingly.

People still using TC++ 3.0 should be hanged till death. Tell that to your instructor/professor.*


----------



## Sykora (Dec 12, 2007)

^^^ Agreed.


----------



## adi007 (Dec 14, 2007)

Yamaraj said:
			
		

> I wonder if it's of any use talking sense into people these days. Turbo C++ is NOT C or even C++. Either ask mods to change the title from "C puzzle" to "Turbo C++ puzzles", or spend some time reading the standard ANSI/ISO C and post accordingly.
> 
> People still using TC++ 3.0 should be hanged till death. Tell that to your instructor/professor.


sorry Yamaraj..
I will take care that this will not happen again...
Will follow strict ANSI/ISO C standards from now on...
By the way which c compiler u use..?

Sorry for not giving puzzle 10 yeterday.Will give puzzle 10 tommorow...


----------



## Yamaraj (Dec 14, 2007)

No need to be sorry. I only want you and others to get better at programming. I use many compilers actually - GCC (On Linux and Cygwin), MinGW (GCC for Win32), Visual C++ 2008 Express Edition, Sun C and C++ on Solaris etc.

If you want a decent ANSI/ISO conforming C compiler for Windows, try Pelles C - *www.smorgasbordet.com/pellesc/ or MinGW.

Things like unbuffered I/O, non-standards functions like clrscr() and getch()/getche() are entirely system or implementation dependent, and likely to distract a potential learner from the path of becoming a real good programmer. In fact, it's the code readability, re-usability and portability that you should be more concerned about.


----------



## adi007 (Dec 15, 2007)

adi007 said:
			
		

> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> *farm3.static.flickr.com/2052/2086499468_1f153310e7_o.gif​
> Currently you are witnessing C puzzle 10
> ...



Puzzle 10 added thread updated...



			
				Yamaraj said:
			
		

> If you want a decent ANSI/ISO conforming C compiler for Windows, try Pelles C - *www.smorgasbordet.com/pellesc/ or MinGW.


^^Thanks Yamaraj for the link...have downloaded Pelles C.It's nice.*gigasmilies.googlepages.com/4.gif


----------



## QwertyManiac (Dec 15, 2007)

Two lines as in two physical lines or prompt/terminal width dependent? Cause I see your 'Jerry' trickling down to the 2nd line character by character.


----------



## a_k_s_h_a_y (Dec 15, 2007)

*Execute in Turbo C only 
You must first save this file in TC directory ONLY save as .C file and then run it in TC
if you save as .CPP then it won't execute 
*

so some graphics in C


```
/* Execute in Turbo C only 
You must first save this file in TC directory as NAME.C only and then run it in TC
if you save as .CPP then it won't execute   */

#include <graphics.h>
#include <dos.h>
#include <conio.h>
main()
{
    int gd=DETECT,gm,button,x,y,x2,y2,i;
    char a;
    x=0;y=0;

    initgraph(&gd,&gm,"");
    setcolor(2);
    setfillstyle(SOLID_FILL,BLACK);
    outtextxy(50,400,"Keep holding Space For Tom to Chase, Any key to Exit ");
    outtextxy(50,430,"hell with the rules this was made by me long back now just edited little ");
    outtextxy(50,450,"i have to study for VTU bye and btw All the best Mr Very Rude Adi");

    for(x=0;x<480;x++)
    {
    outtextxy(x,y,"Tom  Jerry");
    a=getch();
    bar(x,y,x+79,y+10);
    if(a!=' ') exit(0);
    }

    for(x=480;x>0;x--)
    {
    outtextxy(x,y+30,"Tom  Jerry");
    a=getch();
    bar(x,y,x+79,y+50);
    if(a!=' ') exit(0);
    }
    while(!kbhit());
}
```


----------



## Faun (Dec 15, 2007)

a_k_s_h_a_y said:
			
		

> *Execute in Turbo C only
> You must first save this file in TC directory ONLY save as .C file and then run it in TC
> if you save as .CPP then it won't execute
> *
> ...


lol..these quizzies are nuts*farm3.static.flickr.com/2286/2107305542_22d75ef21a_o.png


----------



## The_Devil_Himself (Dec 15, 2007)

^^yea,these compiler specific codes are funny.


----------



## a_k_s_h_a_y (Dec 16, 2007)

T159 said:
			
		

> lol..these quizzies are nuts*farm3.static.flickr.com/2286/2107305542_22d75ef21a_o.png


yeah i did not give into it much .. 
just wrote back the program with slight changes of the version that i already had

its basically Dos Program with DOS.H and i tried compiling it in borland latest but i get errors .. hell lots .. don't know why.

Graphics in C is outdated i think.. but that's what i used for My Text Editor and Graphics Editor Projects in 3rd SEM .. i mean i am using .. still in 3rd Sem lol

i really don't know why newly available compiler fails in this .. !! after all its just C.. about KBHIT function its ok i know its defined in DOS.h
and i could have used sleep() to get out put exactly as need but let it be space bar . i think its cool


----------



## Faun (Dec 16, 2007)

a_k_s_h_a_y said:
			
		

> yeah i did not give into it much ..
> just wrote back the program with slight changes of the version that i already had
> 
> its basically Dos Program with DOS.H and i tried compiling it in borland latest but i get errors .. hell lots .. don't know why.
> ...



turbo c graphics libraries are not ANSI C compliant.
I hated so much using it till 3rd year.


----------



## a_k_s_h_a_y (Dec 16, 2007)

^^ then how do i go about with graphics in C ?

my big text editor and graphics editor projects that i wrote in TC are all waste or what ??


----------



## Faun (Dec 16, 2007)

a_k_s_h_a_y said:
			
		

> ^^ then how do i go about with graphics in C ?
> 
> my big text editor and graphics editor projects that i wrote in TC are all waste or what ??


nothing is waste, all serves for some purpose.
U will need it during ur engg (curse the old syllabus)

Just dont make it mainstream, there are other tools to create graphics.


----------



## a_k_s_h_a_y (Dec 16, 2007)

T159 said:
			
		

> there are other tools to create graphics.


for example ??
no not directx and windows API .. i am trying to stay away from it for some time now
other then that maybe


----------



## Faun (Dec 16, 2007)

a_k_s_h_a_y said:
			
		

> for example ??
> no not directx and windows API .. i am trying to stay away from it for some time now
> other then that maybe


am not aware abt other tools in C, and its hihgly unlikely that u will be allowed to use anyhing other than gcc and turbo c in college. So better stick to old ways for the time being.

i hav learned making UI using JAVA and XUL.


----------



## Yamaraj (Dec 16, 2007)

C doesn't care about graphics, sound or input devices. You must use external libraries and/or system API for that kind of a program.


----------



## Faun (Dec 16, 2007)

Yamaraj said:
			
		

> C doesn't care about graphics, sound or input devices. You must use external libraries and/or system API for that kind of a program.


yeah those 3rd party libraries*farm3.static.flickr.com/2192/2107308402_d580fcfc62_o.png


----------



## anantkhaitan (Dec 16, 2007)

Gr8 thread...
My solution to Problem no. 10

```
#include<conio.h>
#include<stdio.h>
#include<dos.h>
void main()
{
int x=1,y=1,d=1;
char a[]=" Tom  Jerry  ";
while(!kbhit())
     {
     gotoxy(x,y);
     printf(a);
     delay(50);
     x+=d;
     if(x==81&&y==1&&d==1){x=1;y=2;}
     if(x==0&&y==2&&d==-1){x=80;y=1;}
     if(x==69&&y==2&&d==1){d=-1;a[4]=32;a[12]=2;}
     if(x==1&&y==1&&d==-1){d=1;a[4]=2;a[12]=32;}
     }
}
```

Note: _String a[ ] contains that similey *Alt+2* after Tom_ 
And guys I don't have a TC++ compiler so this program was tested by dry run GCC doesn't support conio


----------



## Pathik (Dec 16, 2007)

T159 said:
			
		

> am not aware abt other tools in C, and its hihgly unlikely that u will be allowed to use anyhing other than gcc and turbo c in college. So better stick to old ways for the time being.
> 
> i hav learned making UI using JAVA and XUL.


But isnt XUL used mainly only in firefox extensions??
btw r u also in engg??


----------



## Faun (Dec 17, 2007)

pathiks said:
			
		

> But isnt XUL used mainly only in firefox extensions??
> btw r u also in engg??


 nope XUL is used in songbird player.(its platform independent)

And its all based on XML (the mega player of web based applications), XML can be used to make almost everything.

Everything is getting web based.

yeah am in engg.


----------



## adi007 (Dec 17, 2007)

*gigasmilies.googlepages.com/68.gifsorry,i just forgot to specify another imporatant rule



> Rules
> No user defined functions..
> *only stdio.h,conio.h and string.h are allowed*
> no gotoxy()



now try..*gigasmilies.googlepages.com/yes.gif
and let me give u a hint that it has nothing to do with graphics...*gigasmilies.googlepages.com/16.gif


----------



## anantkhaitan (Dec 17, 2007)

^^ are yaar.. I was using *dos.h* only for delay().. ok if you don't want it then..

```
#include<conio.h>
#include<stdio.h>
void main()
{
int x=1,y=1,d=1;
char a[]=" Tom  Jerry  ";
while(!kbhit())
     {
     gotoxy(x,y);
     printf(a);
     for(long i=0;i<99999;i++); // Time delay loop
     x+=d;
     if(x==81&&y==1&&d==1){x=1;y=2;}
     if(x==0&&y==2&&d==-1){x=80;y=1;}
     if(x==69&&y==2&&d==1){d=-1;a[4]=32;a[12]=2;}
     if(x==1&&y==1&&d==-1){d=1;a[4]=2;a[12]=32;}
     }
}
```

Not using graphics is not a hint but its obvious..


----------



## adi007 (Dec 17, 2007)

first thing there should be smiley..
second jerry should chase tom with a smiley..
third no gotoxy(sorry i didn't specified it in the beginning)...

i will add more rules..
wait till tommorow..
I think i made a mess of this puzzle...*gigasmilies.googlepages.com/39.gif


----------



## anantkhaitan (Dec 17, 2007)

^^
Brother do you want to me to write the program exactly as you have written.. A program can be written in hundred of ways, and now you start adding rules..Its not that I cannot write the program without using *gotoxy()*, but again I will write a program and you will say: "You cannot use this or that"..First of all be clear with your problem. And as far as the competition/contest/(whateva it is) is concern I am seeing that I am the only participant..



			
				adi said:
			
		

> first thing there should be smiley..
> second jerry should chase tom with a smiley..


Have you compiled the program..?? and for the smiley check what I have written earlier #131: 





> String a[ ] contains that similey *(Alt+2)* after Tom


Now you can take this much of pain atleast because i don't have Turbo C++ with me.. rather i don't have DOS with me..


----------



## adi007 (Dec 17, 2007)

i will be clear with my rules tommorow and that will be final..*gigasmilies.googlepages.com/yes.gif
sorry for the trouble..*gigasmilies.googlepages.com/63.gif
i am accesing net from my college and i have no internet connection in my home..
so it is not possible to check ur program..

instead of smiley use some char such as '#'


----------



## anantkhaitan (Dec 17, 2007)

Ok brother bring your rules tomorrow.. here I bring my program (without gotoxy());

```
#include<conio.h>
#include<stdio.h>
void main()
{
int s=0,d=1,j;
char a[]="Tom#  Jerry ";
while(!kbhit())
     {
     clrscr();
     for(j=0;j<s;j++)printf(" ");
     printf(a);
     for(long i=0;i<99999;i++);
     s+=d;
     if(s==149&&d==1){d=-1;a[3]=32;a[11]=35;}
     if(s==0&&d==-1){d=1;a[3]=35;a[11]=32;}
     }
}
```


----------



## adi007 (Dec 18, 2007)

final set of rules



> *
> allowed header files -->stdio.h,conio.h&string.h
> no gotoxy(),clreol(),delline(),kbhit()
> maximum of 4 variables
> ...



if ur compiler doesn't support smiley then some char such as '#'


----------



## Faun (Dec 18, 2007)

restrictions and terms ruined my life *farm3.static.flickr.com/2192/2106525721_b621e4efee_o.png


----------



## QwertyManiac (Dec 18, 2007)

Yeah, why is he asking people to make it exactly as his? Those set of rules are very very specific.


----------



## anantkhaitan (Dec 18, 2007)

Perhaps he is making the rules after seeing my code 

@ adi
Listen brother i have just one thing to say "I GIVE UP". Do you know what is the use of *kbhit* ??? If we use something like *while(!kbhit())* the loop keeps on iterating until you press a key i.e. ending up your program whenever you like, Now tell me does it anywhere hampers/interferes with the logic of the code. I have used 4 variables with a string.. I can write the same program using 2-3 variables without using any string but that will elongate the code...
Every programmer has a unique way of writing .. and what I submitted was my way of writing and you cannot it change by imposing those stupid rules (whateva I submitted U made a new rule against that).. And I am feeling proud that I am disqualified.. Waiting for your code..ATB

And yes forgot to mention about *printf(" ")* replace it by *printf("%c",32)*


----------



## a_k_s_h_a_y (Dec 18, 2007)

yeah that's what i meant
a program can be written in many ways !!
he wants us to think exactly as he does !

that can be done using basics of printf thing ... going back and coming forward .. but now who has time to solve it .. exams are on !!


----------



## Faun (Dec 18, 2007)

a_k_s_h_a_y said:
			
		

> yeah that's what i meant
> a program can be written in many ways !!
> he wants us to think exactly as he does !
> 
> that can be done using basics of printf thing ... going back and coming forward .. but now who has time to solve it .. exams are on !!


 better study for exams dude, ur placement depends on marks.
Alas finally am above all these plcaement tension

yay my 600th post*farm3.static.flickr.com/2355/2107305358_394278500c_o.png


----------



## The_Devil_Himself (Dec 18, 2007)

who said placement depends upon marks?toppers sux and are good for nothing!The guy who got the highest placement in my university in 2005-2006 had 9 backs at the time of interviews!!


----------



## Faun (Dec 18, 2007)

The_Devil_Himself said:
			
		

> who said placement depends upon marks?toppers sux and are good for nothing!The guy who got the highest placement in my university in 2005-2006 had 9 backs at the time of interviews!!


exceptions do occur 

Probably some other qualities helped him, but its a risky matter to depend on this if we can surely secure placement by getting good marks.

After all good marks are not just for placements but also ur parents will be happy that their efforts and resources are not getting wasted.

Btw who said toppers sux ?, i said get good marks just to be on safer side.


----------



## fun2sh (Dec 18, 2007)

The_Devil_Himself said:
			
		

> who said placement depends upon marks?toppers sux and are good for nothing!The guy who got the highest placement in my university in 2005-2006 had 9 backs at the time of interviews!!


yeah! u r right! few girls who r topper in my class knows nothin abt programin!! jst mug up the things! but at least 1 need the grace marks for sittin in placement exams!!!

n guys plz dont talk offtopic here(sorry coz i too did just now)!!! its a very nice thread!


----------



## harryneopotter (Dec 18, 2007)

devil is right in a sense .......toppers sux ..but only who r crammers (unfortunately most toppers are crammers..) and regarding placement, if u fulfill the minimum criteria for a company ... thn it dsnt matter whether u have 71% marks or 91% marks ... it depends solely on ur talent .............


----------



## a_k_s_h_a_y (Dec 18, 2007)

guys guys enough .. adi will start to wonder from where did *#include <placements.h>* come in his programs


----------



## Faun (Dec 18, 2007)

ok guys u win, i had the same notion what you hav now but everything changes. I hav seen all this, this very year (people havin high marks were not even asked any questions at interviews but average students were passed thru trials).

Do you think mass recruiters look for talents, agar aisa hota toh india mein aaj hazaroo einstein hote.

its a fight club discussion so am backing off now. 
Back to topic comrades


----------



## adi007 (Dec 19, 2007)

a_k_s_h_a_y said:
			
		

> yeah that's what i meant
> a program can be written in many ways !!
> he wants us to think exactly as he does !


no a_k_s_h_a_y my intension is not that..
i modified the rules because i later found that the puzzle would become too easy without them..



			
				anantkhaitan said:
			
		

> Perhaps he is making the rules after seeing my code


this is some what true 
but let me say that my intension was not to make u program the way i programmed..
After seeing ur code i found out that the puzzle will be too easy to solve without some rules.So i had to modify the rules



			
				anantkhaitan said:
			
		

> @ adi
> Listen brother i have just one thing to say "I GIVE UP".


don't give up anantkhaitan. the answer to this puzzle is way too easy..
easier than ur old program..



			
				anantkhaitan said:
			
		

> If we use something like *while(!kbhit())* the loop keeps on iterating until you press a key i.e. ending up your program whenever you like,


i already told that tom should chase jerry for *2 lines*...
so there is no necessity for kbhit()



			
				The_Devil_Himself said:
			
		

> who said placement depends upon marks?toppers sux and are good for nothing!The guy who got the highest placement in my university in 2005-2006 had 9 backs at the time of interviews!!


^^I agree with u ..
please start a new thread named 'does placement depends upon marks' in the fight club..
lets see there what others think...


----------



## Pathik (Dec 19, 2007)

The_Devil_Himself said:
			
		

> who said placement depends upon marks?toppers sux and are good for nothing!The guy who got the highest placement in my university in 2005-2006 had 9 backs at the time of interviews!!


+100


----------



## anuj919 (Dec 20, 2007)

Hi Adi   
I think this answer fulfills all your conditions. 


```
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
	int i,j=1;
	long k;
	char a[]="Tom# Jerry ";
	clrscr();
	while(j<=2)
	{
		for(i=0;i<=149;i++)
		{
			printf("%*s",i+strlen(a),a);
			for(k=0;k<9999999;k++);
			clrscr();
		}
		a[3]=' ';a[10]='#';
		for(i=149;i>=0;i--)
		{
			printf("%*s",i+strlen(a),a);
			for(k=0;k<9999999;k++);
			clrscr();
		}
		a[3]='#';a[10]=' ';
		j++;
	}
}
```


----------



## adi007 (Dec 22, 2007)

^^yup u are right..
one point for anuj919 and one for anantkhaitan and a_k_s_h_a_y...



			
				adi007 said:
			
		

> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> *farm3.static.flickr.com/2052/2086499468_1f153310e7_o.gif​
> Currently you are witnessing C puzzle 11
> ...


11th puzzle added!!
Thread updated!!


----------



## adi007 (Dec 24, 2007)

hmm...
no responses..
may be everyone are busy with there exams


----------



## adi007 (Jan 1, 2008)

Puzzle date has been extended till 11th Jan(coz i think many of u have exams like me)


----------



## anuj919 (Jan 1, 2008)

We can use arrays,can't we........


----------



## anantkhaitan (Jan 1, 2008)

Check out :

```
#include<stdio.h>
int main()
        {
        int a,b;
        printf("Enter a Number\n");
        scanf("%d",&a);
        b=10*(a%10)+(a/10);
        printf("The reverse of %d is %d\n",a,b);
        for(b=2;b<=a;b++)
                if(a==b)
                {printf("%d is a prime number\n",a);break;}
                else if(a%b==0)
                {printf("%d is not a prime number\n",a);break;}
        printf("Sum of digits=%d\n",a/10+a%10);
        return 0;
        }
```
This time do not add rules after submitting


----------



## khattam_ (Jan 3, 2008)

Here's the solution which works for all integers:
	
	



```
#include<stdio.h>
#include<conio.h>

void main(void){
int n,i;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);

printf("The reverse of %d is ",n);
i=n;
while(i>0){
printf("%d",i%10);
i/=10;
}

printf("\n%d is ",n);
for(i=2;i<n;i++)
if (n%2==0){ 
printf("not ");
break;
}
printf ("a prime number",n);

i=0;
while(n>0){
i+=n%10;
n/=10;
}

printf("\nSum of digits=%d",i);
getch();
}
```


----------



## maddy354 (Jan 5, 2008)

#include<stdio.h>
 main()
{
     int i,a[10];
     printf("\nenter a number\n");
     scanf("%d",&a[0]);
     a[1]=a[0];a[2]=0;
     for(;a[1]>0;i++)
     {a[2]=a[2]*10+a[1]%10;
     a[1]/=10;
     }
     a[3]=0;
     for(i=2;i<a[0]/2;i++)
     {if(a[0]%i==0)
     a[3]=1;
     }
     printf("\nreverse of %d is %d\n",a[0],a[2]);
     if(a[3]==1)
     printf("\n%d is not prime\n");
     else
     printf("\n%d is prime\n",a[0]);
     return 0;
     }


----------



## adi007 (Jan 12, 2008)

I'm back


anantkhaitan said:


> Check out :
> 
> ```
> #include<stdio.h>
> ...


^^hmm..
Not have compiled ur program but i think it will work only for 2 digit integers..
If it is then ur program is wrong..
The output's that i have given are just examples..It doesn't mean that the program should work only for 2 digit integers..
It must work for all integers (Upto the integers supported by int datatype)..



khattam_ said:


> Here's the solution which works for all integers:
> 
> ```
> #include<stdio.h>
> ...


^^Exellent logic..U got the right answer but i think their is one small mistake

```
for(i=2;i<n;i++)
if (n%2==0)
{ 
printf("not ");
break;
}
```
^^It's not n%2 it's n%i ..



maddy354 said:


> ```
> #include<stdio.h>
> main()
> {
> ...


^^It's right..

Any more different methods to solve this puzzle ...
Puzzle 11 will be posted on monday 14th Jan.


----------



## adi007 (Jan 14, 2008)

adi007 said:


> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> *farm3.static.flickr.com/2052/2086499468_1f153310e7_o.gif​
> Currently you are witnessing C puzzle 12
> ...



puzzle 12 added thread updated


----------



## adi007 (Jan 17, 2008)

hmmm.. 
not even one try..
looks like the puzzle is too difficult or i am not clear in puzzle ..


----------



## rachitpant (Jan 17, 2008)

adi007 said:


> Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka
> 
> *farm3.static.flickr.com/2052/2086499468_1f153310e7_o.gif​
> i entered this thread thinking some1 must be challenging to write a GUI or console based solution for sodoku .
> ...




 i dont see any thing puzzling here
some1 who has spend 3 days  studying c++ will be able to answer this


----------



## fun2sh (Jan 18, 2008)

u forgot to mention the rules!


----------



## adi007 (Jan 18, 2008)

^^i had given the rules already it's in the first post of the thread..
I just quoted that post..but i don't know why the rules disappeared..
Any ways i have edited the post here is the rules


> Rules*
> maximum of 2 header files -stdio.h and conio.h
> no variables,constants
> no structures,pointers,user defined functions..
> ...





rachitpant said:


> i dont see any thing puzzling here
> some1 who has spend 3 days  studying c++ will be able to answer this


take a look at the puzzle now...
*www.thinkdigit.com/forum/showpost.php?p=719822&postcount=163


----------



## QwertyManiac (Jan 18, 2008)

I can't use conio.h on Linux since its a DOS header. Thus you may have to excuse 3 functions of NCURSES am gonna use to emulate the getche() with echo off as required for your output. [NCURSES has only getch() and certain key-break/check functions to use along with it.]

1. initscr() - Required to start a working window for manipulating I/O. Mandatory for ncurses programs, segfaults else.
2. noecho() - Turns off echo. As your program demands. 
3. endwin() - To close the screen started. Complements the 1st allowance. You can treat it as one.

(One thing I don't understand is, getche is supposed to getch() and echo right? Why doesn't your output have any characters then? Anyway, I used noecho() to do so.)

Ps. You have exit() under stdio.h probably, while I need to use stdlib.h. I have no use of stdio.h in my program and hence I guess you can allow me this one more too.

Program:

```
#include<ncurses.h>
#include<stdlib.h>

int main()
{    
    
    [B]initscr();
    noecho();[/B]
    printw("Hello!\nContinue(y/n)\n");
    switch (getch())
    {
        case 121:
            main();
            break;
        case 89:
            main();
            break;
    }
    printw("Bye,press any key to exit");
    getch();
    [B]endwin();[/B]
    exit(0);
}
```

I don't expect this to pass or something, just wished to show that jumping over from TurboCrap stuff to standard code (And even Linux, for that matter) is easier than what most think.

Compile as:

```
gcc name.c -o outname [B]-lncurses[/B]
```

Outputs as:

```
Hello!
Continue(y/n)
Hello!
Continue(y/n)
Bye,press any key to exit
```


----------



## baccilus (Jan 18, 2008)

Find the fault:


```
#include <stdio.h>
main ()
{
    int a, b, sum;
    printf ("Enter a number ");
    scanf("%d",a);
    printf("\nEnter another number ");
    scanf("%d",b);
    sum=a+b;
    printf("\nSum is %d",sum);    
    return 0;
}
```

It is supposed to add two numbers by the way.


----------



## QwertyManiac (Jan 18, 2008)

Your scanf arguments must be addresses and not values. Add an ampersand to each of the variables you use in a scanf statement. 


```
#include <stdio.h>
main ()
{
    int a, b, sum;
    printf ("Enter a number ");
    scanf("%d",[B]&a[/B]);
    printf("\nEnter another number ");
    scanf("%d",[B]&b[/B]);
    sum=a+b;
    printf("\nSum is %d",sum);    
    return 0;
}
```


----------



## d1g1t (Jan 18, 2008)

the scanfs are missing the & (address of) operator


Edit: die Qwerty die


----------



## baccilus (Jan 19, 2008)

Thanks guys.


----------



## adi007 (Jan 20, 2008)

QwertyManiac said:


> I can't use conio.h on Linux since its a DOS header. Thus you may have to excuse 3 functions of NCURSES am gonna use to emulate the getche() with echo off as required for your output. [NCURSES has only getch() and certain key-break/check functions to use along with it.]
> 
> 1. initscr() - Required to start a working window for manipulating I/O. Mandatory for ncurses programs, segfaults else.
> 2. noecho() - Turns off echo. As your program demands.
> ...


^^u solved the puzzle but let me say that u have used several functions but since u are in linux i have excused many of them..Try solving it in windows using conio.h.....
BTW is there any windows emulator c version in linux ..
There are many more ways to solve it..
The puzzle is open till tommorow..


> (One thing I don't understand is, getche is supposed to getch() and echo right? Why doesn't your output have any characters then? Anyway, I used noecho() to do so.)


That's the intresting part of the puzzle..
make getche() work as getch()....


----------



## QwertyManiac (Jan 20, 2008)

adi007 said:


> BTW is there any windows emulator c version in linux


 Are you crazy enough to use ANY means to get the crap Turbo C even on Linux?

I quit!


----------



## adi007 (Jan 20, 2008)

^^ I am just curious whether there is any such stuff or not...
I tried using wine but in vain...


----------



## QwertyManiac (Jan 20, 2008)

adi007 said:


> ^^ I am just curious whether there is any such stuff or not...
> I tried using wine but in vain...


Do you understand what a compiler is supposed to do? And why there are different compilers out there? 

Btw: You can run it under dosbox, since its a DOS compiler set.


----------



## khattam_ (Jan 23, 2008)

Did this under dosbox.
Did not find any function to exit except exit() from stdlib.h. However, other rules have been followed. Keen to see anyone do this by follwoing the rules completely. No loops, no functions and no getch()?? this one is difficult, at least for me...


```
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void main (void)
{
printf("\nHello!\nContinue(y/n)");
if(getche()=='y') main();
printf("\nBye, Press any key to exit.");
getche();
exit(0);
}
```

Maybe we cud clear the thing and reprint the thing. But no looping.??


----------



## QwertyManiac (Jan 23, 2008)

khattam_ said:


> [/code]Maybe we cud clear the thing and reprint the thing. But no looping.??


 No *if* too.


----------



## adi007 (Jan 24, 2008)

khattam_ said:


> Did this under dosbox.
> Did not find any function to exit except exit() from stdlib.h. However, other rules have been followed. Keen to see anyone do this by follwoing the rules completely. No loops, no functions and no getch()?? this one is difficult, at least for me...
> 
> 
> ...



no *if* 
.. and i think ur output will not match with mine coz u see even if press 'y' it will not get displayed on the screen..overall make getche() work like getch()...

The next puzzle will be asked soon..currently busy with my new software..sorry for the delay..till then this puzzle is open for everyone...


----------



## khattam_ (Jan 25, 2008)

ok... i remembered my 1st sem classes and did it. the echoing thing.. Thanks for the hint adi007
\b does the backspace and a space is printed over y.....

```
#include <stdio.h>
#include <conio.h>

void main (void){
printf("\nHello!\nContinue(y/n)");
switch (getche()){
case 'y':
printf("\b ");
main();
break;
default:
printf("\b \nBye, Press any key to exit.");
getche();
}}
```


but still for the exit(), I needed stdlib.h.. 
which i fixed by placing the default: thing..... but I was not sure how this thing worked....

But figured it out later.....


----------



## adi007 (Jan 25, 2008)

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


----------



## khattam_ (Jan 25, 2008)

adi007 said:


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




here you go:


```
#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 ");
}
```


----------



## adi007 (Jan 27, 2008)

^^Right answer...I am impressed...


----------



## vinit suri (Feb 1, 2008)

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........


----------



## khattam_ (Feb 3, 2008)

vinit suri said:


> 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 ;"........
> ...




```
#include <stdio.h>

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


----------



## vinit suri (Feb 7, 2008)

yes dats the right answer.........but dat was 2 simple


----------



## adi007 (Feb 7, 2008)

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..


----------



## khattam_ (Feb 8, 2008)

vinit suri said:


> yes dats the right answer.........but dat was 2 simple


i guess so.

Ok, here's one from my side. The program should output:

```
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.


----------



## redhat (Feb 10, 2008)

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


----------



## QwertyManiac (Feb 10, 2008)

Why don't you start one?


----------



## redhat (Feb 12, 2008)

I would, but i have no puzzles to give.
I wish to SOLVE puzzles


----------



## khattam_ (Feb 26, 2008)

khattam_ said:


> i guess so.
> 
> Ok, here's one from my side. The program should output:
> 
> ...





Since nobody solved it, here's the solution:

```
#include <stdio.h>

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


----------



## vinit suri (Feb 28, 2008)

hey khattam wot does "&&i&&main() " do??


----------



## d1g1t (Feb 29, 2008)

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

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


----------



## khattam_ (Feb 29, 2008)

d1g1t said:


> 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....


----------

