C语言 实验10-1 圆形体体积计算器 (20分)

在这里插入图片描述
课本例题啦,细节稍微有点不同。
友情提示,此题验证一直错误的,建议看一下PI的精度哦(别问我是怎么知道的,一个小时的代价。。。。。)

#include<stdio.h>
#define PI 3.1415926535
void cal(int sel);
double v_ball (void);
double v_cylinder (void);
double v_cone (void);
int main (void)
{
	int sel;
	while (1) {
		printf("1-Ball\n");
		printf("2-Cylinder\n");
		printf("3-Cone\n");
		printf("other-Exit\n");
		printf("Please enter your command:\n");
		scanf("%d", &sel);
		if (sel <1 || sel >3)
			break;
		else 
			cal(sel);
	}
	
	return 0;
}
void cal (int sel)
{
	switch (sel) {
		case 1:
			printf("%.2f\n", v_ball());
			break;
		case 2:
			printf("%.2f\n", v_cylinder());
			break;
		case 3:
			printf("%.2f\n", v_cone());
			break;
	}
}
double v_ball (void)
{
	double r;
	printf("Please enter the radius:\n");
	scanf("%lf", &r);
	return (4.0/3.0*PI*r*r*r);
}
double v_cylinder(void)
{
	double r,h;
	printf("Please enter the radius and the height:\n");
	scanf("%lf %lf", &r, &h);
	return (PI*r*r*h);
}
double v_cone (void)
{
	double r,h;
	printf("Please enter the radius and the height:\n");
	scanf("%lf %lf", &r, &h);
	return (1/3.0*PI*r*r*h);
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值