Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. /* This program takes two inputs acceleration
  3. and mass, and ouputs the force = mass*acceleration */
  4.  
  5. void force(double m, double accel);
  6.  
  7. int main() {
  8. /* Added accel */
  9. double mass, accel;
  10. /* Changed %d to %lf since it is declared with double */
  11. printf("Enter an acceleration: ");
  12. scanf("%lf", &accel);
  13. /* Changed %d again to %lf for the same reason as above */
  14. printf("Enter the mass of the object: ");
  15. scanf("%lf", &mass);
  16.  
  17. force(mass, accel);
  18.  
  19. printf("You entered %lf m/s^2\n", accel);
  20. printf("You entered %lf kg\n", mass);
  21.  
  22. return 0;
  23. }
  24.  
  25. /* Declared mass too */
  26. void force(double m, double accel, double mass) {
  27. mass = m / 1000;
  28.  
  29. printf("The force is %lf milliNewtons\n", mass * accel);
  30.  
  31. accel = accel*1000;
  32.  
  33. printf("The force is %lf Newtons\n\n", mass * accel);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement