fork download
  1. //********************************************************
  2. //
  3. // Midterm Question Triangle
  4. //
  5. // Name: Benjamin Lin
  6. //
  7. // Class: C Programming, Spring 2024
  8. //
  9. // Date: 4/18/2024
  10. //
  11. // Description: Program with six functions that calculate area for six different types of shapes.
  12. //
  13. //********************************************************
  14.  
  15. #include <stdio.h>
  16. #define HALF 0.5
  17.  
  18. float area_of_triangle (float base, float height)
  19. {
  20.  
  21. float area; // area of triangle
  22.  
  23. // compute area of triangle: 1/2 * base * height
  24. area = HALF * base * height;
  25.  
  26. return (area);
  27.  
  28. } // area__of_triangle
  29.  
  30. main ()
  31. {
  32.  
  33. float area; /* the area of the circle */
  34. float base;
  35. float height;
  36.  
  37. printf ("Enter the triangle base: ");
  38. scanf ("%f", &base);
  39.  
  40. printf ("Enter the triangle height: ");
  41. scanf ("%f", &height);
  42.  
  43. area = area_of_triangle (base, height);
  44.  
  45. printf ("The Area of a triangle with a base of %0.2f and a height of %0.2f is %0.2f \n", base, height, area);
  46.  
  47. return (0);
  48.  
  49. }
Success #stdin #stdout 0s 5268KB
stdin
10
11
stdout
Enter the triangle base: Enter the triangle height: The Area of a triangle with a base of 10.00 and a height of 11.00 is 55.00