void swap(int* a, int* b, int* c) { int first = *a; int third = *c; int second = *b; if (*b > first) { first = *b; } if (*c > first) { first = *c; } if (*a < third) { third = *a; } if (*b < third) { third = *b; } if (*a<first && *a>third) { second = *a; } if (*c<first && *c>third) { second = *b; } *c = first; *b = second; *a = third; } int main() { int a, b, c = 0; scanf("%d%d%d", &a, &b, &c); swap(&a, &b, &c); if (a + b <= c || a + c <= b || b + c <= a || a <= 0 || b <= 0 || c <= 0) printf("no"); else if ( a * a + b * b < c * c) printf("dunjiao"); else if (a * a + b * b == c * c) printf("zhijiao"); else printf("ruijiao"); return 0; } 该代码有何错误
时间: 2024-04-09 10:28:57 浏览: 105
c语言swap(a,b)值交换的4种实现方法
5星 · 资源好评率100%
该代码存在一个错误。在函数`swap`中,参数`int* c`应为`int* b`,参数`int* b`应为`int* c`。正确的代码如下:
```c
void swap(int* a, int* b, int* c)
{
int first = *a;
int third = *c;
int second = *b;
if (*b > first)
{
first = *b;
}
if (*c > first)
{
first = *c;
}
if (*a < third)
{
third = *a;
}
if (*b < third)
{
third = *b;
}
if (*a<first && *a>third)
{
second = *a;
}
if (*c<first && *c>third)
{
second = *c;
}
*c = first;
*b = second;
*a = third;
}
int main()
{
int a, b, c = 0;
scanf("%d%d%d", &a, &b, &c);
swap(&a, &c, &b);
if (a + b <= c || a + c <= b || b + c <= a || a <= 0 || b <= 0 || c <= 0)
printf("no");
else if ( a * a + b * b < c * c)
printf("dunjiao");
else if (a * a + b * b == c * c)
printf("zhijiao");
else
printf("ruijiao");
return 0;
}
```
请注意,我已经将函数`swap`中的参数进行了更正,并在`main`函数中调用了`swap(&a, &c, &b)`来正确交换`a`和`c`的值。
阅读全文