clayy24

lab8

Oct 2nd, 2018
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /* LAB 8 – Pythagoras Lives!!!
  2. Write a program that will calculate the hypotenuse of a right triangle given the
  3. two leg sides from the user.
  4. Be sure to use functions. Ensure that the calculation function you write has type
  5. double for its arguments and return type.
  6. You may use a new precompiled function found in the <math.h> header file. It
  7. is prototyped as follows:
  8. double sqrt (double x);
  9. This function will find the square root of some variable or expression ‘x’ and return the
  10. square root approximation as a double.
  11. Display the output in a well formatted easy to read table. Work that printf()
  12.  
  13.  
  14. PSEUDOCODE
  15. 1) The first leg of the triangle, the second leg of the triangle
  16.  
  17. 2) double leg1, leg2;
  18.  
  19. 3 & 4) I. Get user input
  20. A. prompt user using printf() and use scanf() to load values into leg1 and leg2
  21. II. Perform calculations
  22. A. create a new function hypotenuse to perform the calculations in
  23. B. use sqrt(pow(legone,2)+pow(legtwo, 2)) to calculate the hypotenuse
  24. III. Display the results
  25. A. use printf() and field width specifiers to display results in a formatted table
  26. */
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #include <stdio.h>
  33. #include <math.h>
  34.  
  35. double hypotenuse();
  36.  
  37. int main()
  38. {
  39. double leg1, leg2, hypval;
  40.  
  41. printf("Enter the first leg: ");
  42. scanf("%lf", &leg1);
  43. printf("Enter the second leg: ");
  44. scanf("%lf", &leg2);
  45.  
  46. hypval = hypotenuse(leg1, leg2);
  47.  
  48. printf("%11s%11s%12s\n", "Leg one", "Leg two", "Hypotenuse");
  49. printf("%11lf%11lf%12lf\n", leg1, leg2, hypval);
  50.  
  51.  
  52. return 0;
  53. }
  54.  
  55. double hypotenuse(double legone, double legtwo)
  56. {
  57. double hyp;
  58. hyp = sqrt(pow(legone,2)+pow(legtwo,2));
  59. return hyp;
  60. }
Add Comment
Please, Sign In to add comment