编写一程序从键盘输入圆锥体的半径r 高度h 并计算其体积

有圆锥体的面积得,V=1/3sh(s为圆锥体的底面积)  直接计算得

直接进行顺序结构设计就可以计算出其体积 

在写程序时,由于整数运算具有封闭性,因此采用  1.0/3

代码展示如下:

#include 
#define PI 3.14

int main()
{
	float r,h,V,S;
	printf("Please enter the radius r of the cone:\n");
	scanf("%f", &r);
	printf("Please enter the height h of the cone:\n");
	scanf("%f", &h);
	S = PI * r * r;
	V = 1.0/ 3 * S * h;
	printf("The volume of the cone is:%f\n", V);

	return 0;
}

你可能感兴趣的:(算法,c++,c语言)