/*
2、用三个函数分别实现求三角形,正方形,圆形面积(所有底高半径都由用户
输入);在主函数中,通过用户不同的选择分别进行调用;
*/
#include <stdio.h>
#define P 3.14
double sanjiao(double di,double gao)
{
double mianji = (di * gao)/2 ;
return mianji;
}
double zhengfangxing(double bian)
{
double mianji2 = bian*bian;
return mianji2;
}
double yuanxing(double r)
{
double mianji3 = P*r*r;
return mianji3;
}
void main()
{
int shuru;
double shuju1,shuju2,shuju3,shuju4,jieguo;
printf("输入数字代码,可得出你选择的图形面积.(1.三角形. 2.正方形. 3.圆形):\n");
scanf("%d",&shuru);
switch(shuru)
{
case 1:
printf("输入三角的低和高(逗号隔开)\n");
scanf("%lf,%lf",&shuju1,&shuju2);
jieguo = sanjiao(shuju1,shuju2);
printf("面积为:%.2lf\n",jieguo);
break;
case 2:
printf("输入正方形的边长:\n");
scanf("%lf",&shuju3);
jieguo = zhengfangxing(shuju3);
printf("面积为%.2lf\n",jieguo);
break;
case 3:
printf("输入圆形的半径:\n");
scanf("%lf",&shuju4);
jieguo = yuanxing(shuju4);
printf("面积为%.2lf\n",jieguo);
break;
}
}