#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();
}
Puzzle 3 added.Thread updatedadi007 said:Here is the 3rd C Puzzle
Here is a simple C program
NOW ALL I WANT YOU TO DO IN THIS PROGRAM IS TO COMPLETE DECLARATIONS SO THAT IT MACTHES THE OUTPUT.Code:#include<s[B][/B]tdio.h> #include<conio.h> void main() { /*Complete the declartions*/ clrscr(); a=sunday; b=monday; c=tuesday; d=wednesday; e=thursday; f=friday; g=saturday; printf("%d/n%d/n%d/n%d/n%d/n%d/n%d/n",a,b,c,d,e,f,g); getch(); }
Code:Output: 1 2 3 4 5 6 7
The following are the Rules:
1.sunday,monday,tuesday,wednesday,thursday,friday,saturday etc are not varibles nor constants.Means
are not allowedCode:int sunday=1; or #define sunday 1
2.a,b,c,d,e,f,g are not of int datatype
^^ not allowedCode:int a;
Note :Specify your modified program along with the answer
Awards gallary:
Puzzles solved :2
me (If no one gets the solution then points will be for me) 0
saurabh kakkar 1
eggman 1
fun2sh 1
Leading:saurabh kakkar ,eggman,fun2sh
#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();
}
#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();
}
adi007 said:^^ i want only program.
Please specify your modified program along with the answer.
no responses???
#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();
}
#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();
}
adi007 said:Here is the 3rd C Puzzle
Here is a simple C program
NOW ALL I WANT YOU TO DO IN THIS PROGRAM IS TO COMPLETE DECLARATIONS SO THAT IT MACTHES THE OUTPUT.Code:#include<stdio.h> #include<conio.h> void main() { /*Complete the declartions*/ clrscr(); a=sunday; b=monday; c=tuesday; d=wednesday; e=thursday; f=friday; g=saturday; printf("%d/n%d/n%d/n%d/n%d/n%d/n%d/n",a,b,c,d,e,f,g); getch(); }
Code:Output: 1 2 3 4 5 6 7
The following are the Rules:
1.sunday,monday,tuesday,wednesday,thursday,friday,saturday etc are not varibles nor constants.Means
are not allowedCode:[B]int sunday=1;[/B] [B]or [/B] [B]#define sunday 1[/B]
2.a,b,c,d,e,f,g are not of int datatype
^^ not allowedCode:[B]int a;[/B]
Note :Specify your modified program along with the answer
Awards gallary:
Puzzles solved :2
me (If no one gets the solution then points will be for me) 0
saurabh kakkar 1
eggman 1
fun2sh 1
Leading:saurabh kakkar ,eggman,fun2sh
#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();
}
No buddy there is no need to spectify 'enum days'i just think that you have to specify 'enum days' instead of simply days.
Did you executed the program saurabh...
adi007 said:
The answer to this puzzle will be given on Nov 5 if no one solves the puzzle
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.
Here is the 4th C Puzzle[A bit complicated one]
Here is a C program to find the area of the circle
NOW ALL I WANT YOU TO DO IN THIS PROGRAM IS TO COMPLETE PROGRAM SO THAT IT MACTHES THE OUTPUT.Code:#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(); }
I hope you have understood the purpose of the program i.e,calculate the area of the circle by taking value of pi upto certain decimal pointCode: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
There is another important point that i wished to specify i.e,
The output should be like this
but not thisCode:The value of pi taken=3.141 and the area of the circle is 2010.522690
Code:The value of pi taken=3.141000 and the area of the circle is 2010.522690
Similarly,for various value of precision the ouput should be
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
3 - 25.3 - 3.141 - 2010.522690
4 - 25.3 - 3.1415 - 2010.842735
5 - 25.3 - 3.14159 - 2010.900343
6 - 25.3 - 3.141592 - 2010.901623
7 - 25.3 - 3.1415926 - 2010.902007
8 - 25.3 - 3.14159265 - 2010.902039
The following are the Rules:
1.If and it's variants,switch,?,for,while,do..while,goto -->not allowed
2.No new variables
3.No new header file other than math.h,conio.h,stdio.h
Note :Specify your modified program along with the answer
Awards gallary:
Puzzles solved :3
me (If no one gets the solution then points will be for me) 0
saurabh kakkar 2
eggman 1
fun2sh 1
Leading:saurabh kakkar
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!!
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
#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();
}
/**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
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
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
3 - 25.3 - 3.141 - 2010.522690
4 - 25.3 - 3.1415 - 2010.842735
5 - 25.3 - 3.14159 - 2010.900343
6 - 25.3 - 3.141592 - 2010.901623
7 - 25.3 - 3.1415926 - 2010.902007
8 - 25.3 - 3.14159265 - 2010.902039
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