C program (MENU DRIVEN) to find the area of circle, triangle,
equilateral triangle, right angled triangle, rectangle,
square, trapezium, rhombus and parallelogram.
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <math.h> int main()
{
float area, s;
int a, b, c, length, breath, height, radius, side, ch;
clrscr();
while(1) {
/* get the option from user */
printf("1. Circle\t2. Triangle\n");
printf("3. Rectangle\t4. Square\n");
printf("5. Trapezoid\t6. Rhombus\n");
printf("7. Parallelogram\t8.Equilateral triangle \n");
printf("9.aright angled triangle\t10.Exit\n");
printf("Enter your choice:");
scanf("%d", &ch);
switch(ch) {
case 1: printf("Enter the radius of the circle:");
scanf("%d", &radius);
area = 3.14 * radius * radius;
printf("Area of Circle: %f\n", area);
break;
case 2:
printf("Enter the sides of the triangle:");
scanf("%d%d%d", &a, &b, &c);
s = (1.0 * (a + b + c)) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area of Triangle: %f\n", area);
break;
case 3:
printf("Enter the length and breath of Rectangle:");
scanf("%d%d", &length, &breath);
area = length * breath;
printf("Area of Rectangle: %f\n", area);
break;
case 4:
printf("Enter the side of a square:");
scanf("%d", &side);
area = side * side;
printf("Area of square: %f\n", area);
break;
case 5:
printf("Enter the length of parallel sides(a & b):");
scanf("%d%d", &a, &b);
printf("Enter the height:");
scanf("%d", &height);
area = ((a + b) * 1.0 * height) / 2;
printf("Area of trapezoid: %f\n", area);
break;
case 6:
printf("Enter the diagonal values(p & q):");
scanf("%d%d", &a, &b);
area = a * b / 2;
printf("Area of rhombus: %f\n", area);
break;
case 7:
printf("Enter the breath and height of parallelogram:");
scanf("%d%d", &b, &height);
area = b * height * 1.0 / 2;
printf("Area of parallelogram: %f\n", area);
break;
case 8:
printf("Enter the side of a Equilateral triangle:");
scanf("%d", &a);
area = (sqrt(3)/4)*(a*a);
printf("Area of Equilateral triangle: %f\n", area);
break;
case 9:
printf("Enter the value of a and b for right angled triangle:");
scanf("%d%d", &a,&b);
area = (1/2)*(a*b);
printf("Area of right angled triangle: %f\n", area);
break;
case 10:
exit(0);
default:
printf("Wrong Option!!\n");
break;
}
getch();
return 0;
}
}
OUTPUT:
1. Circle 2. Triangle
3. Rectangle 4. Square
5. Trapezoid 6. Rhombus
7. Parallelogram 8.Equilateral triangle
9.aright angled triangle 10.Exit
Enter your choice: 2
Enter the size of the triangle: 2 5 6
Area of Triangle: 4.683749
equilateral triangle, right angled triangle, rectangle,
square, trapezium, rhombus and parallelogram.
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <math.h> int main()
{
float area, s;
int a, b, c, length, breath, height, radius, side, ch;
clrscr();
while(1) {
/* get the option from user */
printf("1. Circle\t2. Triangle\n");
printf("3. Rectangle\t4. Square\n");
printf("5. Trapezoid\t6. Rhombus\n");
printf("7. Parallelogram\t8.Equilateral triangle \n");
printf("9.aright angled triangle\t10.Exit\n");
printf("Enter your choice:");
scanf("%d", &ch);
switch(ch) {
case 1: printf("Enter the radius of the circle:");
scanf("%d", &radius);
area = 3.14 * radius * radius;
printf("Area of Circle: %f\n", area);
break;
case 2:
printf("Enter the sides of the triangle:");
scanf("%d%d%d", &a, &b, &c);
s = (1.0 * (a + b + c)) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area of Triangle: %f\n", area);
break;
case 3:
printf("Enter the length and breath of Rectangle:");
scanf("%d%d", &length, &breath);
area = length * breath;
printf("Area of Rectangle: %f\n", area);
break;
case 4:
printf("Enter the side of a square:");
scanf("%d", &side);
area = side * side;
printf("Area of square: %f\n", area);
break;
case 5:
printf("Enter the length of parallel sides(a & b):");
scanf("%d%d", &a, &b);
printf("Enter the height:");
scanf("%d", &height);
area = ((a + b) * 1.0 * height) / 2;
printf("Area of trapezoid: %f\n", area);
break;
case 6:
printf("Enter the diagonal values(p & q):");
scanf("%d%d", &a, &b);
area = a * b / 2;
printf("Area of rhombus: %f\n", area);
break;
case 7:
printf("Enter the breath and height of parallelogram:");
scanf("%d%d", &b, &height);
area = b * height * 1.0 / 2;
printf("Area of parallelogram: %f\n", area);
break;
case 8:
printf("Enter the side of a Equilateral triangle:");
scanf("%d", &a);
area = (sqrt(3)/4)*(a*a);
printf("Area of Equilateral triangle: %f\n", area);
break;
case 9:
printf("Enter the value of a and b for right angled triangle:");
scanf("%d%d", &a,&b);
area = (1/2)*(a*b);
printf("Area of right angled triangle: %f\n", area);
break;
case 10:
exit(0);
default:
printf("Wrong Option!!\n");
break;
}
getch();
return 0;
}
}
OUTPUT:
1. Circle 2. Triangle
3. Rectangle 4. Square
5. Trapezoid 6. Rhombus
7. Parallelogram 8.Equilateral triangle
9.aright angled triangle 10.Exit
Enter your choice: 2
Enter the size of the triangle: 2 5 6
Area of Triangle: 4.683749
0 comments:
Post a Comment