求个大佬弄个简单的C语言计算三角形正方形圆的面积和周长,用函数
非常感谢,我是一个菜鸟,参考一下。
程序代码:#include <stdio.h>
#include <math.h>
float LStriangle(float a,float b,float c,char type)
{
float p;
switch (type)
{
case 'l':
return a + b + c;
case 's':
p = (a + b + c) / 2;
return sqrt(p*(p - a)*(p - b)*(p - c));
default:
break;
}
printf("type 类型异常\n");
}
float LSsquare(float a,char type)
{
switch (type)
{
case 'l':
return 4*a;
case 's':
return a*a;
default:
break;
}
printf("type 类型异常\n");
}
float LScircle(float r,char type)
{
switch (type)
{
case 'l':
return 2*3.14*r;
case 's':
return 3.14*r*r;
default:
break;
}
printf("type 类型异常\n");
}
int main()
{
float Striangle = LStriangle(6,8,10,'s');
printf("Striangle = %.2f\n", Striangle);
getchar();
}可以自己调用一下








