View Code of Problem 49

        #include <stdio.h>
        int main(){
          int n;
          scanf("%d",&n);
          int a[n],i;
          for(i=0;i<n;i++){
            scanf("%d",&a[i]);
          }
          int max=0,min=0,temp;
          for(i=0;i<n;i++){
            if(a[max]<a[i]){max=i;}
          }
          temp=a[max];
          a[max]=a[n-1];
          a[n-1]=temp;
          for(i=0;i<n;i++){
            if(a[min]>a[i]){min=i;}
          }
          temp=a[min];
          a[min]=a[0];
          a[0]=temp;
          for(int i=0;i<n-1;i++){
            printf("%d ",a[i]);
          }
          printf("%d\n",a[n-1]);
        }

Double click to view unformatted code.


Back to problem 49