【C语言练习题】判断三角形的类型
【摘要】
代码
//triangle.c#include <stdio.h> void triangle( int a, int b, int c ); // 函数声明 --- 作用域 void main(void){ int x,y,z; printf("please input (length):\n"); printf("...
代码
-
//triangle.c
-
#include <stdio.h>
-
-
-
void triangle( int a, int b, int c ); // 函数声明 --- 作用域
-
-
void main(void)
-
{
-
int x,y,z;
-
printf("please input (length):\n");
-
printf("x:");
-
scanf("%d",&x);
-
printf("y:");
-
scanf("%d",&y);
-
printf("z:");
-
scanf("%d",&z);
-
-
triangle( x,y,z );//判断三角形类型
-
}
-
-
-
void triangle( int a, int b, int c )
-
{
-
int temp;
-
-
if( a > b )
-
{//如果a比较b大,就相互转换
-
temp = a;
-
a = b;
-
b = temp;
-
}
-
if( a > c )
-
{//如果a比较c大,就相互调换
-
temp = a;
-
a = c;
-
c = temp;
-
}
-
if( b > c )
-
{//如果b比较c大,就相互调换
-
temp = b;
-
b = c;
-
c = temp;
-
}
-
-
if( a+b <= c )
-
{
-
printf("不是三角形!!\n");
-
return ;
-
}
-
else
-
{
-
if( a == b )
-
{
-
if( a != c )
-
printf("等腰三角\n");
-
else
-
printf("等边三角\n");
-
}
-
else
-
{
-
printf("是个三角形\n");
-
}
-
}
-
}
结果
文章来源: blog.csdn.net,作者:hinzer,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/feit2417/article/details/85220496
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)