Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
272
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 <stdbool.h>
  3.  
  4. int main(void)
  5. {
  6.     int num[100];
  7.     bool not_sorted = true;
  8.     bool swap;
  9.     int amount, buff;
  10.        
  11.     printf("Podaj ilość liczb, które chcesz wpisać do tablicy: ");
  12.     scanf("%d", &amount);
  13.    
  14.     for(int i = 0; i < amount; i++)
  15.     {
  16.         printf("Podaj liczbę: ");
  17.         scanf("%d", &num[i]);
  18.     }
  19.    
  20.     while(not_sorted)
  21.     {
  22.         swap = false;
  23.         for(int j = 0; j < amount; j++)
  24.         {
  25.             if(num[j] > num[j+1])
  26.             {
  27.                 swap = true;
  28.                 buff = num[j+1];
  29.                 num[j+1] = num[j];
  30.                 num[j] = buff;
  31.             }
  32.         }
  33.         if(!swap)
  34.             not_sorted = false;
  35.     }
  36.    
  37.     for(int k = 0; k < amount; k++)
  38.     {
  39.         printf("%d ", num[k]);
  40.     }
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement