PPRuNe Forums - View Single Post - C Code Problem
Thread: C Code Problem
View Single Post
Old 1st November 2006 | 21:23
  #8 (permalink)  
rotorcraig
 
Joined: Jul 2002
Posts: 537
Likes: 0
From: Northampton UK
Okay, here's my punt. Caveats are (1) I haven't written C for 5 years at least and (2) I don't have a C compiler so may not even compile!!!
// Include the Standard IO header
#include <stdio.h>
void main()
{
// t represents time
// h represents height of the ball
float t,h;
// initialise both to zero (ie at time 0, height is 0)
t=0;
h=0;
// loop until height goes negative (ball falls below zero)
while (h>=0)
{
// height = 15 x time - 4.9 x time(squared)
h=(15*t)-(4.9*t*t);
// print time, height and a new line
printf("%f %f\n",t,h);
// add 0.2 seconds to time
t=t+0.2;
}
}
RC

Last edited by rotorcraig; 1st November 2006 at 23:24.
rotorcraig is offline  
Reply