In C++, the following code would produce the output listed below
int main() {
const double GRAVITY_MPS2 = 9.8;
int seconds = 10;
std::cout << "Secs Distance" << endl
<< fixed << showpoint << setprecision(2);
for (int i = 1; i <= seconds; i++) {
std::cout << setw(4) << i << " " << (0.5*GRAVITY_MPS2*i*i) << endl;
}
return 0;
}
Seconds | Distance |
---|---|
1 | 4.90 |
2 | 19.60 |
3 | 44.10 |
4 | 78.40 |
5 | 122.50 |
6 | 176.40 |
7 | 240.10 |
8 | 313.60 |
9 | 396.90 |
10 | 490.00 |