#include<stdio.h> int main() { printf("我是光电12203项琳清\n"); int score_1,score_2,score_3; printf("请输入三位学生的成绩:"); scanf("%d%d%d",&score_1,&score_2,&score_3); void sequence(int score_1,int score_2,int score_3); sequence(score_1,score_2,score_3); return 0; } void sequence(int score_1,int score_2,int score_3) { int a[3]={score_1,score_2,score_3}; int i,j,temp; for(i=0;i<3;i++) { for(j=i+1;j<3;j++) { if(a[i]>a[j]) temp=a[i]; a[i]=a[j]; a[j]=temp; } printf("%d ",a[i]); } }代码错误
时间: 2024-01-22 07:02:33 浏览: 28
在主函数中调用了 sequence 函数,但是函数的声明和定义应该在主函数之前。所以需要将 sequence 函数的定义移动到主函数之前,或者在主函数前加上函数声明。同时在 sequence 函数中,if 判断语句的括号没有写全,应该将三个语句都放在括号内。修改后的代码如下:
```
#include<stdio.h>
void sequence(int score_1,int score_2,int score_3);
int main() {
printf("我是光电12203项琳清\n");
int score_1,score_2,score_3;
printf("请输入三位学生的成绩:");
scanf("%d%d%d",&score_1,&score_2,&score_3);
sequence(score_1,score_2,score_3);
return 0;
}
void sequence(int score_1,int score_2,int score_3) {
int a[3]={score_1,score_2,score_3};
int i,j,temp;
for(i=0;i<3;i++)
{
for(j=i+1;j<3;j++)
{
if(a[i]>a[j]) {
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
printf("%d ",a[i]);
}
}
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)