1158: 又是排序(指针专题)expected declaration or statement at end of input

版权声明:写作不易,转载请注明作者和出处。如果对您有帮助,支付宝搜索534165486领个小红包,谢谢~~~///(^v^)\\\~~~ https://blog.csdn.net/Bear_Two_/article/details/82559679

1158: 又是排序(指针专题)

时间限制: 1 Sec  内存限制: 128 MB

题目描述

将输入的四个整数按由大到小的顺序输出。 
已定义如下swap函数,可实现形参pa和pb所指内存单元的内容交换。请务必使用本函数实现两个变量内容的互换。 
void swap( int *pa, int *pb) 

int t; 
t=*pa; *pa=*pb; *pb=t; 

输入

输入4个整数,用空格隔开。

输出

输出排序后的4个整数,由空格隔开。输出占一行。

样例输入

4 3 5 2

样例输出

5 4 3 2

expected declaration or statement at end of input


#include<stdio.h>
#define maxn 100
void swap( int *pa, int *pb);
int main(){
    int i,j,a[maxn];
    for(i=0;i<4;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<3;i++){
        for(j=i+1;j<4;j++){
            if(a[i]<a[j]) swap(&a[i],&a[j]);
        }
    }
    for(i=0;i<4;i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}//   <---  就是缺少这个位置的括号
void swap( int *pa, int *pb)
{
    int t;
    t=*pa; *pa=*pb; *pb=t;
}

今天刷题的时候碰见上面这个错误,令我很奇怪,后来查询原因,是少了一个大括号。

支付宝搜索"534165486"领个小红包吧
支付宝搜索"534165486"领个小红包吧

猜你喜欢

转载自blog.csdn.net/Bear_Two_/article/details/82559679