/* * File Name : free_fall_d_vs_time.c * Title : Free-fall distance vs. time * Author : Buff Furman * Created : 12SEP2009 * Revised : 12SEP2009 * Version : 1.0 * Description : Calculates the distance vs. time of a free-falling mass * Inputs : none * Outputs : time in seconds, distance in meters * Method : Declare and initialize variables * While time <= 10 * calculate d print time and distance increment time * End * Revision History: * Date Who Description of Change * ------- --------- --------------------------- * 17SEP2012 BF Modified printf() formatting * 12SEP2009 BF Created program */ /*---------Include Files--------------*/ #include /* standard IO library routines, like printf, scanf */ /*---------Macros---------------------*/ #define G 9.81 /* standard gravitational constant, m/s^2 */ //float g = 9.81; /* alternative approach using a variable */ /*---------Function Prototypes--------*/ /* none in this program */ /*---------Global Variables-----------*/ /* none in this program */ /*---------Body of Program Code-------*/ int main(void) { /* Declare variables */ float t; /* time variable */ double d; /* distance in meters */ /* Initialize variables */ t = 0.0; d = 0.0; /* Print header row for time and distance */ printf("time, sec distance, m\n" "--------- -----------\n"); /* Loop to calculate and print time and distance */ while( t <= 10.01) { /* Note curly brace for compound statement */ d = 0.5*G*t*t; printf("%9.1f %6.2f\n", t, d); t = t + 0.1; } /* Finish */ return 0; } /*---------Function Definitions-------*/ /* none in this program */