Calculate the time it takes a ball to hit the ground after it has been dropped from an 800-foot tower. - C++ Language Basics

C++ examples for Language Basics:Console

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.

Demo Code

#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;
}

Result


Related Tutorials