
在C编程语言中,我们可以利用结构体来找到圆的面积、圆柱体的面积和体积。
s.areacircle = (float)pi*s.radius*s.radius;
s.areacylinder = (float)2*pi*s.radius*s.line + 2 * s.areacircle;
s.volumecylinder = s.areacircle*s.line;
参考下面给出的算法,通过使用结构体来计算圆和圆柱体的面积以及其他参数。
步骤1 - 声明结构体成员。
步骤2 - 声明并初始化输入变量。
步骤3 - 输入圆柱体的长度和半径。
步骤4 - 计算圆的面积。
步骤5 - 计算圆柱体的面积。
步骤6 - 计算圆柱体的体积。
以下是使用结构体来计算圆和圆柱体的面积以及其他参数的C程序 -
实时演示
#include<stdio.h>
struct shape{
float line;
float radius;
float areacircle;
float areacylinder;
float volumecylinder;
};
int main(){
struct shape s;
float pi = 3.14;
//taking the input from user
printf("Enter a length of line or height : ");
scanf("%f",&s.line);
printf("Enter a length of radius : ");
scanf("%f",&s.radius);
//area of circle
s.areacircle = (float)pi*s.radius*s.radius;
printf("Area of circular cross-section of cylinder : %.2f</p><p>",s.areacircle);
//area of cylinder
s.areacylinder = (float)2*pi*s.radius*s.line + 2 * s.areacircle;
printf("Surface area of cylinder : %.2f</p><p>", s.areacylinder);
//volume of cylinder
s.volumecylinder = s.areacircle*s.line;
printf("volume of cylinder : %.2f</p><p>", s.volumecylinder);
return 0;
}当上述程序被执行时,它产生以下输出 −
Enter a length of line or height: 34 Enter a length of radius: 2 Area of circular cross-section of cylinder: 12.56 Surface area of cylinder: 452.16 volume of cylinder : 427.04
以上就是使用结构体编写的C程序,用于计算圆和圆柱体的面积的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号