C++ examples for Language Basics:Console
for calculating the time in seconds it takes to fall a given distance in feet:
time = sqrt(2 * distance / g)
g is the gravitational constant equal to 32.2 ft/sec2.
#include <iostream> #include <cmath> using namespace std; int main()//from ww w .j ava2 s. c o m { int height; double time; height = 800; time = sqrt(2 * height / 32.2); cout << "It will take " << time << " seconds to fall " << height << " feet.\n"; return 0; }