/************************************************************************* * C语言(s = v*t + a*t*t/2)Demo * 声明: * 闲来无聊,写个物理公式(s = v*t + a*t*t/2)程序。 * * 2015-7-4 晴 深圳 南山平山村 曾剑锋 ************************************************************************/#include#include #include #include int main (int argc, char** argv){ //初始度,也就是第一次速度 int first_speed = -500; //每个时间节点的速度 int speed = 0; //加速度g int g = 100; //时间计数器 int time = 0; //位移 int dispalcement = 0; printf ("\nfirst_speed = %4d; g = %3d\n\n", first_speed, g); while (1) { //计算节点速度 speed = first_speed + g * time; //计算位移 dispalcement = first_speed * time + ((g * time * time) / 2); printf ("time = %2d; speed = %4d; dispalcement = %5d\n", time, speed, dispalcement); //时间计数器自加 time++; if (time > 10) break; }}