使用switch case语句编写的C程序,用于计算几何图形的面积

#include
void main(){
int fig_code;
float side, base, length, breadth, height, area, radius;
printf(“————————-

“);
printf(” 1 –> Circle

使用switch case语句编写的C程序,用于计算几何图形的面积

“);
printf(” 2 –> Rectangle

“);
printf(” 3 –> Triangle

“);
printf(” 4 –> Square

“);
printf(“————————-

“);
printf(“Enter the Figure code

“);
scanf(“%d”, &fig_code);
switch(fig_code){
case 1:
printf(” Enter the radius

“);
scanf(“%f”,&radius);
area=3.142*radius*radius;
printf(“Area of a circle=%f

“, area);
break;
case 2:
printf(” Enter the breadth and length

“);
scanf(“%f %f”,&breadth, &length);
area=breadth *length;
printf(“Area of a Rectangle=%f

“, area);
break;
case 3:
printf(” Enter the base and height

“);
scanf(“%f %f”, &base, &height);
area=0.5 *base*height;
printf(“Area of a Triangle=%f

“, area);
break;
case 4:
printf(” Enter the side

“);
scanf(“%f”, &side);
area=side * side;
printf(“Area of a Square=%f

“, area);
break;
default:
printf(” Error in figure code

“);
break;
}
}

发布于 2023-09-02 16:40:57
收藏
分享
海报
0 条评论
117
上一篇:如何使 C# 代码可重用? 下一篇:在Python中,将K添加到列元组列表中的最小元素
目录

    推荐阅读

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码