7-5 圆形体体积计算器 (20 分)
生活随笔
收集整理的這篇文章主要介紹了
7-5 圆形体体积计算器 (20 分)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本題要求實(shí)現(xiàn)一個(gè)常用圓形體體積的計(jì)算器。計(jì)算公式如下:
- 球體體積?V=34?πr3,其中r是球體半徑。
- 圓柱體體積?V=πr2h,其中r是底圓半徑,h是高。
- 圓錐體體積?V=31?πr2h,其中r是底圓半徑,h是高。
輸入格式:
在每次計(jì)算之前,要求輸出如下界面:
1-Ball 2-Cylinder 3-Cone other-Exit Please enter your command:然后從標(biāo)準(zhǔn)輸入讀進(jìn)一個(gè)整數(shù)指令。
輸出格式:
如果讀入的指令是1或2或3,則執(zhí)行相應(yīng)的體積計(jì)算;如果是其他整數(shù),則程序結(jié)束運(yùn)行。
- 當(dāng)輸入為1時(shí),在計(jì)算球體體積之前,打印Please enter the radius:,然后讀入球體半徑,完成計(jì)算;
- 當(dāng)輸入為2時(shí),在計(jì)算圓柱體體積之前,打印Please enter the radius and the height:,然后讀入底圓半徑和高,完成計(jì)算;
- 當(dāng)輸入為3時(shí),在計(jì)算圓錐體體積之前,打印Please enter the radius and the height:,然后讀入底圓半徑和高,完成計(jì)算。
計(jì)算結(jié)果在一行內(nèi)輸出,保留小數(shù)點(diǎn)后兩位。
輸入樣例:
1 2 3 2.4 3 0輸出樣例:
1-Ball 2-Cylinder 3-Cone other-Exit Please enter your command: Please enter the radius: 33.51 1-Ball 2-Cylinder 3-Cone other-Exit Please enter your command: Please enter the radius and the height: 18.10 1-Ball 2-Cylinder 3-Cone other-Exit Please enter your command:?Warning!:題不難,但這個(gè)題的圓周率居然要精確到后十位也是給我整神完.........
代碼如下:
#include<stdio.h> #define PI 3.1415926535 /* Author:海藍(lán)可知天湛date:2022-3-1location:居家隔離(′。_。`)........ */ void menu(){printf("1-Ball\n2-Cylinder\n3-Cone\nother-Exit\nPlease enter your command:\n"); } //菜單界面可視化 void Ball(double *ans,double r){printf("Please enter the radius:\n");scanf("%lf",&r);double v=4.0*PI*r*r*r/3;*ans=v; } //球體類(lèi) void Cylinder(double *ans,double r,double h){printf("Please enter the radius and the height:\n");scanf("%lf %lf",&r,&h);double v=PI*r*r*h;*ans=v; } //圓柱體類(lèi) void Cone(double *ans,double r,double h){printf("Please enter the radius and the height:\n");scanf("%lf %lf",&r,&h);double v=PI*r*r*h/3;*ans=v; } //圓錐類(lèi) int main(){int a=1;double answer,r,h;while(a<4&&a>0){menu();scanf("%d",&a);switch(a){case 1:Ball(&answer,r);printf("%.2f\n",answer);break;case 2:Cylinder(&answer,r,h);printf("%.2f\n",answer);break;case 3:Cone(&answer,r,h);printf("%.2f\n",answer);break;default:break;}}return 0; }總結(jié)
以上是生活随笔為你收集整理的7-5 圆形体体积计算器 (20 分)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 如何有效的进行7S管理_7S巡检管理系统
- 下一篇: 为什么前几年谷歌力推的模块化手机现在没动