当前位置:网站首页>"Fundamentals of program design" Chapter 10 function and program structure 7-1 circular volume calculator (20 points)
"Fundamentals of program design" Chapter 10 function and program structure 7-1 circular volume calculator (20 points)
2022-07-21 11:34:00 【Cha ran o】
This problem requires the realization of a commonly used calculator for the volume of circular bodies . The calculation formula is as follows :
- Sphere volume V=34πr3, among r It's the radius of the sphere .
- Cylinder volume V=πr2h, among r Is the radius of the bottom circle ,h It's high .
- Cone volume V=31πr2h, among r Is the radius of the bottom circle ,h It's high .
Input format :
Before each calculation , The following interface is required to be output :
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
Then read in an integer instruction from standard input .
Output format :
If the read instruction is 1 or 2 or 3, Then perform the corresponding volume calculation ; If other integers , The program ends .
- When the input is 1 when , Before calculating the volume of the sphere , Print
Please enter the radius:
, Then read in the radius of the sphere , Complete the calculation ; - When the input is 2 when , Before calculating the volume of the cylinder , Print
Please enter the radius and the height:
, Then read in the radius and height of the bottom circle , Complete the calculation ; - When the input is 3 when , Before calculating the volume of the cone , Print
Please enter the radius and the height:
, Then read in the radius and height of the bottom circle , Complete the calculation .
The calculation results are output in one line , Keep two decimal places .
sample input :
1
2
3
2.4 3
0
No blank lines at the end
sample output :
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:
No blank lines at the end
#include<stdio.h>
#include<math.h>
#define pi 3.1415926535
int main()
{
int n;
double r,h;
while(1)
{
printf("1-Ball\n2-Cylinder\n3-Cone\nother-Exit\nPlease enter your command:\n");
scanf("%d",&n);
switch(n)
{
case 1:{
printf("Please enter the radius:\n");
scanf("%lf",&r);
printf("%.2lf\n",4.0*pi*pow(r,3)/3);
break;
}
case 2:{
printf("Please enter the radius and the height:\n");
scanf("%lf%lf",&r,&h);
printf("%.2lf\n",pi*pow(r,2)*h);
break;
}
case 3:{
printf("Please enter the radius and the height:\n");
scanf("%lf%lf",&r,&h);
printf("%.2lf\n",pi*pow(r,2)*h/3);
break;
}
default:return 0;
}
}
return 0;
}
边栏推荐
猜你喜欢
HTB-Lame
K3s deploy rancher
Wechat applet 03 data hijacking agent and event binding
京东云联合Forrester咨询发布混合云报告 云原生成为驱动产业发展新引擎
网络安全学习(九)综合实验&PKI
"Hisense's B-side" technology exhibition opens! Hisense B2B represents the first collective appearance of products!
Pycharm configuration
2021-09-16
Shandong University, Beijing post, Harbin Institute of technology | multimodal dialog systems with dual knowledge enhanced generic trained language model
Network Security Learning (VI) DNS deployment and security
随机推荐
php 获取缩略图
RichTextbox 操作
Which securities company has the lowest Commission for opening an account for stock speculation? Is it safe to open an account on your mobile phone
416. 分割等和子集
2021-09-16
416. Segmentation and subsets
移动边缘计算终端如何赋能高校学习空间智慧管理
在win7 64 上安装scikitlearn的悲惨经历
sqlilabs less-26~26a
lotus-bench 1.17.0-rc3 Benchmarks
微信小程序 25 npm模块和PubSubJS实现页面通讯
sqlilabs less-25~25a
HTB-Lame
Development direction and problems of optaplanner
微信小程序 22 recommend和songDetail初步搭建
Kubevirt manages virtual machines
Network Security Learning (VI) DNS deployment and security
执行ls /dev/pts为什么这么慢?
2021-9-19
OptaPlanner 发展方向与问题