fork download
  1. #include <stdio.h>
  2. #define HALF 0.5
  3.  
  4. // ***********************************************************
  5. //
  6. // Function: area_of_trapezoid
  7. //
  8. // Description: Calculates the Area of a trapezoid given the height
  9. // and length of sides a and b
  10. //
  11. // Parameter: a - length of side a
  12. // b - length of side b
  13. // h - vertical height
  14. //
  15. // Returns: area - Calculated area of the trapezoid
  16. //
  17. // ************************************************************
  18.  
  19. float area_of_trapezoid (float a, float b, float h)
  20. {
  21.  
  22. float area; // area of trapezoid
  23.  
  24. // compute area of trapezoid: 1/2(a + b) * h
  25. area = HALF * (a + b) * h;
  26.  
  27. return (area);
  28.  
  29. } // area_of_trapezoid
  30.  
  31. int main(void)
  32.  
  33. {
  34.  
  35.  
  36. float area; /* the area of the circle */
  37. float a;
  38. float b;
  39. float h;
  40.  
  41. printf ("Enter the side a length: ");
  42. scanf ("%f", &a);
  43.  
  44. printf ("Enter the side a length: ");
  45. scanf ("%f", &b);
  46.  
  47. printf ("Enter the height: ");
  48. scanf ("%f", &h);
  49.  
  50. /* Pass value1 to the square function, process it and return the */
  51. /* the squared value into the answer local variable */
  52. area = area_of_trapezoid (a, b, h);
  53.  
  54. printf ("The Area of a trapezoid with a side of %0.2f and a side of %0.2f and a height of %0.2f is %0.2f \n", a, b, h, area);
  55.  
  56. return (0);
  57. }
  58.  
Success #stdin #stdout 0.01s 5284KB
stdin
3
4
7
stdout
Enter the side a length: Enter the side a length: Enter the height: The Area of a trapezoid with a side of 3.00 and a side of 4.00 and a height of 7.00 is 24.50