一、运行结果;
二、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
//定义π常量的值;
# define π 3.141526
int main()
{
//初始化变量值;
float r, h, S1, S2, P1, V1, V2;
int judge = 0;
//提示用户;
printf("**********************************************************************\n");
printf("********求与圆、圆柱和圆球有关的面积和体积:r是半径,h是高************\n");
printf("\n");
//获取用户输入的值;
printf("请输入r的值:");
scanf("%f", &r);
printf("请输入h的值:");
scanf("%f", &h);
printf("\n");
//提示用户
printf("**********************请选择要进行的操作******************************\n");
printf("1.求圆周长************************************************************\n");
printf("2.求圆面积************************************************************\n");
printf("3.求圆球表面积********************************************************\n");
printf("4.求圆球体积**********************************************************\n");
printf("5.求圆柱体积**********************************************************\n");
printf("0.退出程序************************************************************\n");
printf("**********************************************************************\n");
printf("\n");
//获取用户选择;
printf("您希望进行的操作是:");
scanf("%d", &judge);
//判断运算;
switch (judge)
{
case 1:
//计算;
P1 = 2 * π * r;
//输出结果;
printf("圆的半径为:%.2f,周长为:%.2f\n", r, P1);
break;
case 2:
//运算;
S1 = π * r * r;
//输出结果;
printf("圆的半径为:%.2f,面积为:%.2f\n", r, S1);
break;
case 3:
//运算;
S2 = 4 * π * r * r;
//输出结果;
printf("圆球的半径为:%.2f,表面积为:%.2f\n", r, S2);
break;
case 4:
//运算;
V1 = 4.0 / 3.0 * π * r * r * r;
//输出结果;
printf("圆球的半径为:%.2f,体积为:%.2f\n", r, V1);
break;
case 5:
//运算;
V2 = (π * r * r) * h;
printf("圆柱的半径为:%.2f,体积为:%.2f\n", r, V2);
//输出;
break;
}
return 0;
}
三、N-S流程图;