fork(1) download
  1. //********************************************************
  2. //
  3. // Midterm Question 1
  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.  
  17. #define PI 3.14 /* define the value of PI as a constant */
  18.  
  19. float area_of_circle (float radius)
  20. {
  21.  
  22. float area; /* area of a circle */
  23.  
  24. /* compute area of a circle: PI * radius squared */
  25. area = PI * radius * radius;
  26.  
  27. return (area);
  28. }
  29.  
  30. main ()
  31. {
  32.  
  33. float area; /* the area of the circle */
  34. float radius; /* radius of a circle to be entered */
  35.  
  36. printf ("Enter the circle radius: ");
  37. scanf ("%f", &radius);
  38.  
  39. /* Pass value1 to the square function, process it and return the */
  40. /* the squared value into the answer local variable */
  41. area = area_of_circle (radius);
  42.  
  43. printf ("The Area of a Circle with a radius of %0.2f is %0.2f \n", radius, area);
  44.  
  45. return (0);
  46.  
  47. }
Success #stdin #stdout 0s 5296KB
stdin
10
stdout
Enter the circle radius: The Area of a Circle with a radius of 10.00 is 314.00