BanyRule

15. ssort

Jul 24th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. /*Задание 15. Простая сортировка*/
  2. #include <stdio.h>
  3.  
  4. void sort(int a[], int n)
  5. {
  6.     int i, j, key;
  7.  
  8.     for(j = 1; j < n; ++j){
  9.         key = a[j];
  10.         for(i = j - 1; i >= 0 && a[i] > key; --i)
  11.             a[i + 1] = a[i];
  12.         a[i + 1] = key;
  13.     }
  14. }
  15.  
  16. int main(void) {
  17.     int n, a[64];
  18.    
  19.     scanf("%d\n", &n);
  20.     for(int i = 0; i < n; ++i)
  21.         scanf("%d", &a[i]);
  22.    
  23.     sort(a, n);
  24.     for(int i = 0; i < n; ++i)
  25.         printf("%d ", a[i]);
  26.        
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment