C++ double type calculation

Introduction

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()/*ww w .ja v a2 s.com*/
{
   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;
}



PreviousNext

Related