-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball2.cpp
More file actions
46 lines (34 loc) · 999 Bytes
/
ball2.cpp
File metadata and controls
46 lines (34 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//==================================================
//ball2.cpp
//Code to compute the eventual overall height and velocity of a ball
//launched with given initial velocity on Earth and Mars
#include <iostream>
using namespace std;
int main()
{
double g=9.81;//acceleration due to gravity
cout<<"Input the initial velocity (m/s):> ";
double v0;
cin>> v0 ;
cout<< " Input the time (s):> ";
double t;
cin>> t;
//Results on Earth
cout<< "==========================="//
<< endl;
cout<< "Earth:"<<endl;
cout<< "The velocity at time " <<t<< " is "
<< v0 - g*t <<endl;
cout<< "and the height is "
<< v0*t - (g*t*t)/2 << endl;
//Results on Mars
g=3.63;//Acceleration due to gravity on Mars
cout<< "==========================="//
<< endl;
cout<< "Mars:"<<endl;
cout<< "The velocity at time " <<t<< " is "
<< v0 - g*t <<endl;
cout<< "and the height is "
<< v0*t - (g*t*t)/2 << endl;
return 0;
}