日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

函数程序设计——圆形体体积计算器

發(fā)布時間:2024/1/1 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 函数程序设计——圆形体体积计算器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本題要求實現(xiàn)一個常用圓形體體積的計算器。計算公式如下:
? 球體體積 V=34πr3,其中r是球體半徑。
? 圓柱體體積 V=πr2h,其中r是底圓半徑,h是高。
? 圓錐體體積 V=31πr2h,其中r是底圓半徑,h是高。
輸入格式:
在每次計算之前,要求輸出如下界面:
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
然后從標(biāo)準(zhǔn)輸入讀進一個整數(shù)指令。
輸出格式:
如果讀入的指令是1或2或3,則執(zhí)行相應(yīng)的體積計算;如果是其他整數(shù),則程序結(jié)束運行。
? 當(dāng)輸入為1時,在計算球體體積之前,打印Please enter the radius:,然后讀入球體半徑,完成計算;
? 當(dāng)輸入為2時,在計算圓柱體體積之前,打印Please enter the radius and the height:,然后讀入底圓半徑和高,完成計算;
? 當(dāng)輸入為3時,在計算圓錐體體積之前,打印Please enter the radius and the height:,然后讀入底圓半徑和高,完成計算。
計算結(jié)果在一行內(nèi)輸出,保留小數(shù)點后兩位。
輸入樣例:
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:

程序

#include<stdio.h> double Vball(double r); double Vcylinder(double r,double h); double Vcone(double r,double h); int main() {int x;double r,h;while(1){printf("1-Ball\n2-Cylinder\n3-Cone\nother-Exit\nPlease enter your command:\n");scanf("%d",&x);if(x!=1&&x!=2&&x!=3)break;switch(x){case 1: printf("Please enter the radius:\n");scanf("%lf",&r);printf("%.2lf\n",Vball(r));break;case 2: printf("Please enter the radius and the height:\n");scanf("%lf %lf",&r,&h);printf("%.2lf\n",Vcylinder(r,h));break;case 3: printf("Please enter the radius and the height:\n");scanf("%lf %lf",&r,&h);printf("%.2lf\n",Vcone(r,h));break; } }return 0; }double Vball(double r) {double v;v = 4.0/3*3.14159265358979323846*r*r*r;return v; }double Vcylinder(double r,double h) {double v;v =3.14159265358979323846*r*r*h;return v; }double Vcone(double r,double h) {double v;v =3.14159265358979323846*r*r*h/3;return v; }

結(jié)果

總結(jié)

以上是生活随笔為你收集整理的函数程序设计——圆形体体积计算器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。