Advertisement
rana1704

Selection sort find minimum value

Sep 21st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int i,j,p,a[100],swap,n;
  5.     printf("Enter the number=");
  6.     scanf("%d",&n);
  7.  
  8.     for(i=1;i<=n;i++)
  9.     {
  10.         scanf("%d",&a[i]);
  11.     }
  12.     for(i=1;i<=n-1;i++)
  13.      {
  14.         p=i;
  15.         j=i+1;
  16.  
  17.         while(j<=n)
  18.        {
  19.             if (a[p]>a[j])
  20.             {
  21.                 p=j;
  22.             }
  23.             j++;
  24.         }
  25.         swap=a[i];
  26.         a[i]=a[p];
  27.         a[p]=swap;
  28.  
  29.     }
  30.     for(i=1;i<=n;i++)
  31.     {
  32.         printf("%d",a[i]);
  33.     }
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement