-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMenu Driven circle,triangle.cpp
117 lines (105 loc) · 2.2 KB
/
Menu Driven circle,triangle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#define pi 3.142
float A_circle(float); //area of circle
int C_circle(float); //circumference of circle
int A_square(float); //area of square
int V_sphere(float); //volume of shpere
int A_triangle(float,float); //area of triangle
int A_rectangle(float,float); //area of rectangle
int main()
{
int num,choice;
float r,l,h;
do
{
printf("\nENTER YOUR CHOICE\n\n1.Area of circle\n2.Circumference of circle\n3.Area of square");
printf("\n4.Volume of sphere\n5.Area of triangle\n6.Area of rectangle\n\n");
scanf("%d",&num);
switch(num)
{
case 1:
printf("\nEnter the Radius of circle:");
scanf("%f",&r);
printf("The Area of the circle is %.2f.\n\n",A_circle(r));
break;
case 2:
printf("\nEnter the Radius of circle:");
scanf("%f",&r);
C_circle(r);
break;
case 3:
printf("\nEnter the Lenght of sqaure:");
scanf("%f",&l);
A_square(l);
break;
case 4:
printf("\nEnter the Radius of sphere:");
scanf("%f",&r);
V_sphere(r);
break;
case 5:
printf("\nEnter the Length & Height of triangle respectively:\n");
scanf("%f%f",&l,&h);
A_triangle(l,h);
break;
case 6:
printf("\nEnter the Length & breadth of rectangle respectively:\n");
scanf("%f%f",&l,&h);
A_rectangle(l,h);
break;
default:
printf("INVALID NUMBER\n\n");
}
printf("DO YOU WANT TO CONTINUE: (1/0)\n");
scanf("%d",&choice);
}
while(choice==1);
return 0;
}
float A_circle(float r)
{
float z;
if (r>0)
{
z= (pi*r*r);
return z;
}
else
{
printf("Radius can't be Negative\n\n");
}
}
int C_circle(float r)
{
if (r>0)
{
printf("The Circumference of the circle is %.2f.\n\n",(2*pi*r));
}
else
{
printf("Radius can't be Negative\n\n");
}
}
int A_square(float l)
{
printf("The Area of square is %.2f.\n\n",(l*l));
}
int V_sphere(float r)
{
if (r>0)
{
printf("The Volume of sphere is %.2f.\n\n",(1.3333*(pi*r*r*r))); //(4/3)=1.3333
}
else
{
printf("Radius can't be Negative\n\n");
}
}
int A_triangle(float l,float h)
{
printf("The Area of triangle is %.2f.\n\n",0.5*l*h); //(1/2)=0.5
}
int A_rectangle(float l,float h)
{
printf("The Area of rectangle is %.2f.\n\n",l*h);
}