【C语言】计算自由落体时间的小程序

#include<stdio.h>
#include<math.h>
#define g 9.8
int main(){
	float high=0;
	float time=0;
	char key;
	while(1){
		printf("\n\t计算物体由静止自由落体时间(g=9.8):\n");
		printf("\t**输入-9退出**\n");
		printf("\t请输入高度(单位m):  ");
		scanf("%f",&high);
		if(high==-9) { 
			printf("\t退出程序?(Y/N)  ");
			getchar();
			scanf("%c",&key);
			if(key==89||key==121){
				printf("\t程序退出...\n");
				break;
			}
		}
		else if(high<=0) {
			printf("\t高度应大于0,请重新输入...\n");
		}	
		else{
			time=pow(2*high/g,1);
			printf("\t下落时间t=%.5f s\n",time);
		}
	}
	return 0;
}
发布了18 篇原创文章 · 获赞 0 · 访问量 353

猜你喜欢

转载自blog.csdn.net/qq_43750882/article/details/103531368