fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. //We define g as a constant
  4. #define g 9.8
  5.  
  6. int main()
  7. {
  8. //We define all variables we're going to use..
  9. float v0,h,t,vy,v;
  10. //We ask for horizontal speed and altitude from the user.
  11. printf("Enter initial horizontal speed: ");
  12. scanf("%f",&v0);
  13. printf("\nEnter the altitude the object's thrown: ");
  14. scanf("%f",&h);
  15. //We calculate t and print it out.
  16. t=sqrt(h*2/g);
  17. printf("\n\nTime: %f\n",t);
  18. //We don't need horizontal distance anywhere else.
  19. //So we don't calculate it into a variable.
  20. printf("Horizontal distance: %f\n",v0*t);
  21. //We calculate the vertical speed.
  22. vy=g*t;
  23. printf("Vertical impact speed: %f\n",vy);
  24. //We calculate the impact speed with pythagoras...
  25. printf("Total impact speed: %f\n",sqrt(pow(v0,2)+pow(vy,2)));
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 4248KB
stdin
20
10
stdout
Enter initial horizontal speed: 
Enter the altitude the object's thrown: 

Time: 1.428571
Horizontal distance: 28.571430
Vertical impact speed: 14.000000
Total impact speed: 24.413111