Advertisement
fatman01923

Sorting arrays in N-1 time. C(Language) (Not my code)

May 21st, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #define N 100
  7.  
  8. int main(){
  9.     int i, j, n, temp;
  10.     int a[N];
  11.    
  12.     printf("How many members will the array have?\n");
  13.     scanf(" %d", &n);
  14.    
  15.     printf("Enter the array: \n");
  16.    
  17.     for(i=0;i<n;i++){
  18.         scanf("%d", &a[i]);
  19.     }
  20.    
  21.     printf("\nOriginal List\n");
  22.    
  23.     for(i=0;i<n;i++){
  24.         printf("%d \n", a[i]);
  25.     }
  26.    
  27.     for(i=0;i<n-1;i++){
  28.         for(j=0; j<n-1; j++){
  29.             if(a[j]>a[j+1]){
  30.                 temp = a[j];
  31.                 a[j]=a[j+1];
  32.                 a[j+1]=temp;
  33.                 }
  34.             }
  35.     }
  36.    
  37.    
  38.     printf("\nSorted List\n");
  39.     for(i=0;i<n;i++){
  40.         printf("%d \n", a[i]);
  41.     }
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement