代码如下:
#include <stdio.h>
#include <stdlib.h>
#define EPSINON 1e-3
#define ABS(a) (((a)>0)?(a):(-a)) //?:不支持表达式嵌套
#define ZERO(x) ((x)>-EPSINON &&(x)<EPSINON)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
float a, b, c
float max, mid, min
char input_err_flag = 0
char judge_err_flag = 0
int equal(float a, float b)
{
float tmp
tmp = a - b
tmp = ZERO(ABS(tmp))
return tmp
}
void input(void)
{
a = b = c = 0
printf("输入三条边的值:")
scanf("%f %f %f",&a, &b, &c)
if(!(a>0) || !(b>0) || !(c>0))
{
input_err_flag = 1
}
}
void sort(void)
{
max = MAX(MAX(a,b),c)
min = MIN(MIN(a,b),c)
if(MAX(a,b) <c)
mid = MAX(a,b)
else
mid = MAX(MIN(a,b),c)
}
void judge(void)
{
float max_square, mid_square, min_square, tmp
if(max >= (mid+min))
{
judge_err_flag = 1
}
else
{
max_square = max * max
mid_square = mid * mid
min_square = min * min
tmp = mid_square + min_square
if(equal(mid,min) || equal(max, mid))
{
if(equal(mid, min))
{
if(mid == max)
puts("等边三角形。")
else if(equal(max_square, tmp))
puts("等腰直角三角形。")
else if(max_square <tmp)
puts("等腰锐角三角形。")
else
puts("等腰钝角三角形。")
}
else
{
if(equal(min, mid))
puts("等边三角形。")
else
puts("等腰锐角三角形。")
}
}
else if(equal(max_square, tmp))
puts("直角三角形。")
else if(max_square <tmp)
puts("锐角三角形。")
else
puts("钝角三角形。")
}
}
int main(void)
{
char cs, ch
do
{
input()
sort()
judge()
if(input_err_flag)
{
input_err_flag = 0
while((cs=getchar())!='\n' &&(cs=getchar())!=EOF)
printf("输入错误,a b c必须大于零,是否新输入(y/n):")
}
else if(judge_err_flag)
{
judge_err_flag = 0
while((cs=getchar())!='\n' &&(cs=getchar())!=EOF)
printf("组不成三角形,是否重新输入(y/n):")
}
else
{
while((cs=getchar())!='\n' &&(cs=getchar())!=EOF)
printf("是否再输入一组数据(y/n):")
}
ch = getchar()
}
while(ch=='y' || ch=='Y' || ch=='\n')
puts("Goodbye!")
return 0
}
你对r赋值的时候用了两个等于号“==”,赋值用一个等于号,判断 的时候采用两个!而且输出语句应该放在第一个if外面,应该就这两个问题,代码如下:
#include <stdio.h>
int main(){
int a, b, c, r
printf("Please input three integers:\n")
scanf("%d%d%d",&a,&b,&c)
if(a == b ==c) r = 3
else{
if(a + b >c &&a - b <c){
if(b + c >a &&b - c <a){
if(a + c >b &&a - c <b){
if(a * a == b * b + c * c || b * b == a * a +c * c || c * c == a * a + b * b)
r = 1
else if((a == b &&a != c) || (b == c &&a != b )|| (a ==c &&b != a))
r = 2
else
r = 0
}
else
r = -1
}
else
r = -1
}
else
r =-1
}
if(r == -1)
printf("Tt's not an integer.")
else if(r == 0)
printf("It's an scalenous triangle.")
else if(r == 1)
printf("It's an right-angeld triangle.")
else if(r == 2)
printf("It's an isosceles triangle.")
else if(r == 3)
printf("It's an equilateral triangle.")
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)