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

2023年 9月 2日 65.6k 0

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

");
printf(" 1 --> Circle

");
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;
}
}

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论