Advertisement
skb50bd

Sorting

Apr 4th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n,i,j,k,min;
  5.     printf("How Many Inputs? : ");
  6.     scanf("%d",&n);
  7.     int a[n];
  8.     printf("\nNow Start Entering %d Inputs\n",n);
  9.     for(i=0 ; i<n ; i++) //for taking inputs into array
  10.     {
  11.         scanf("%d",&a[i]);
  12.     }
  13.     for(i=0 ; i<n-1 ; i++) //for sorting
  14.     {
  15.         min=a[i];
  16.         for(j=i+1 ; j<n ; j++)
  17.         {
  18.             if(min>a[j])
  19.             {
  20.                 min=a[j];
  21.                 a[j]=a[i];
  22.                 a[i]=min;
  23.             }
  24.         }
  25.     }
  26.     printf("Here's the Sorted Version: ");
  27.     for(i=0 ; i<n ; i++) //for printing
  28.         printf("%d ",a[i]);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement