Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
76
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. #include <stdlib.h>    /* srand, rand */
  3. #include <time.h>      /* time */
  4.  
  5. #define SIZE 5 // większe od 0
  6.  
  7. int main()
  8. {
  9.     srand (time(NULL));
  10.  
  11.     int tab[] = { 4, 2, 5, 1, 7 };
  12.  
  13.     for(int i = 0; i < SIZE; i++ )
  14.         tab[i] = rand()%20+1;
  15.  
  16.  
  17.     for(int i = 0; i < SIZE; i++ )
  18.         for(int k = 1; k < SIZE; k++ )
  19.         {
  20.             if( tab[k-1] > tab[k] )
  21.             {
  22.                 int buff = tab[k];
  23.                 tab[k] = tab[k-1];
  24.                 tab[k-1] = buff;
  25.             }
  26.         }
  27.  
  28.     printf("Posortowane: ");
  29.     for(int i = 0; i < SIZE; i++ )
  30.         printf("%d ",tab[i]);
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement