设为首页 加入收藏

TOP

问题一百三十六:三角形类问题 (一)
2014-11-23 22:13:06 来源: 作者: 【 】 浏览:2
Tags:问题 一百三十六 三角形
[plain] #include
#include
#include

float calculate_perimeter(float x, float y, float z);
float calculate_area(float x, float y, float z);
int judge_triangle(float x, float y, float z);
int judge_righttriangle(float x, float y, float z);
int judge_isoscelestriangle(float, float y, float z);
int judge_equilateraltriangle(float x, float y, float z);
int main()
{
float x;
float y;
float z;

scanf("%f %f %f", &x, &y, &z);

if(judge_triangle(x, y, z))
{
printf("The area of a triangle is %f.\nThe perimeter of a triangle is %f.\n",
calculate_area(x, y, z), calculate_perimeter(x, y, z));
if(judge_righttriangle(x, y, z))
{
printf("The triangle is right triangle!\n");
}
else
{
printf("The triangle is not right triangle!\n");
}

if(judge_isoscelestriangle(x, y, z))
{
printf("The triangle is isoscelestriangle!\n");
}
else
{
printf("The triangle is not isoscelstriangle\n");
}

if(judge_equilateraltriangle(x, y, z))
{
printf("The triangle is equilateraltriangle!\n");
}
else
{
printf("The triangle is not equlateraltriangle!\n");
}
}
else
{
printf("x, y and z cann`t form a triangle!\n");
}

system("pause");
return 0;
}

//definetion of function
//**judge triangle
int judge_triangle(float x, float y, float z)
{
int flag;

flag=0;

if(x+y> z || x+z> y || y+z> x)
{
flag=1;
}

return flag;
}

//**calculate perimeter
float calculate_perimeter(float x, float y, float z)
{
float perimeter;

perimeter=x+y+z;

return perimeter;
}

//**calculate area
float calculate_area(float x, float y, float z)
{
float s;
float area;

s=calculate_perimeter(x, y, z)/2;
area=sqrt((s-x)*(s-y)*(s-z)*s);

return area;
}

//**judge righttriagnle
int judge_righttriangle(float x, float y, float z)
{
int flag;

flag=0;

if(x*x+ y*y ==z*z || x*x+ z*z==y*y || z*z+ y*y==x*x)
{
flag=1;
}

return flag;
}

//** judge isoscelestriangle
int judge_isoscelestriangle(float x, float y, float z)
{
int flag;

flag=0;

if(x==y || x==z || y==z)
{
if(x==y && y==z && x==z)
{
flag=0;
}
else
{
flag=1;
}
}

return flag;
}

//**judge equilateraltriangle
int judge_equilateraltriangle(float x, float y, float z)
{
int flag;
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇问题一百三十四:数组逆序 下一篇问题一百三十八:指针操作学生结..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: