fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int choice;
  5. double radius, length, width, side, base, height, area;
  6.  
  7. printf("--- Area Calculator ---\n");
  8. printf("1. Circle\n2. Rectangle\n3. Square\n4. Triangle\n");
  9. printf("Enter your choice (1-4): ");
  10. scanf("%d", &choice);
  11.  
  12. switch (choice) {
  13. case 1:
  14. printf("Enter radius: ");
  15. scanf("%lf", &radius);
  16. area = 3.14159 * radius * radius;
  17. printf("Area of Circle = %.2f\n", area);
  18. break;
  19. case 2:
  20. printf("Enter length and width: ");
  21. scanf("%lf %lf", &length, &width);
  22. area = length * width;
  23. printf("Area of Rectangle = %.2f\n", area);
  24. break;
  25.  
  26. case 3:
  27. printf("Enter side length: ");
  28. scanf("%lf", &side);
  29. area = side * side;
  30. printf("Area of Square = %.2f\n", area);
  31. break;
  32.  
  33. case 4:
  34. printf("Enter base and height: ");
  35. scanf("%lf %lf", &base, &height);
  36. area = 0.5 * base * height;
  37. printf("Area of Triangle = %.2f\n", area);
  38. break;
  39. default:
  40. printf("Invalid choice!\n");
  41. }
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 5304KB
stdin
triangle
stdout
--- Area Calculator ---
1. Circle
2. Rectangle
3. Square
4. Triangle
Enter your choice (1-4): Invalid choice!