Area Calculation for Various Shapes
#include <stdio.h>
int main() {
int choice;
float base, height, side, radius;
printf("Choose a shape to find the area:\n");
printf("1. Triangle\n2. Square\n3. Circle\n4. Rectangle\n");
printf("Enter your choice (1-4): ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the base and height of the triangle: ");
scanf("%f %f", &base, &height);
printf("Area of the triangle: %.2f\n", 0.5 * base * height);
break;
case 2:
printf("Enter the side of the square: ");
scanf("%f", &side);
printf("Area of the square: %.2f\n", side * side);
break;
case 3:
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
printf("Area of the circle: %.2f\n", 3.14 * radius * radius);
break;
case 4:
printf("Enter the length and width of the rectangle: ");
scanf("%f %f", &base, &height);
printf("Area of the rectangle: %.2f\n", base * height);
break;
default:
printf("Invalid choice! Please enter a number between 1 and 4.\n");
}
return 0;
}