SHARE
TWEET

Sort ( Ascending ) task 1

Mr_TRex Jun 21st, 2020 788 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int a[200];
  5.     int n,x,i,j,index,min;
  6.     scanf("%d",&n);
  7.     for(x=0; x<n; x++)
  8.     {
  9.         scanf("%d",&a[x]);
  10.     }
  11.     for(i=0; i<n; i++)
  12.     {
  13.         min=a[i];
  14.         index=-1;
  15.         for(j=i+1; j<n; j++)
  16.         {
  17.             if(a[j]<min)
  18.             {
  19.                 min=a[j];
  20.                 index=j;
  21.             }
  22.         }
  23.         if(index!=-1)
  24.         {
  25.             a[index]=a[i];
  26.             a[i]=min;
  27.         }
  28.     }
  29.     for(i=0; i<n; i++)
  30.     {
  31.         printf("%d ",a[i]);
  32.     }
  33.  
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top