Advertisement
Wojtekd

Zadanie1 Lab3 ZAISD

Oct 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. void prostew(int* a, int n)
  6. {
  7.     int i,j;
  8.     int x; 
  9.    
  10.     for(i = 1; i < n; i++)
  11.     {
  12.         x = a[i];
  13.         j = i-1;
  14.        
  15.         while(x < a[j])
  16.         {
  17.             a[j+1] = a[j];
  18.             j = j-1;       
  19.         }
  20.                
  21.         a[j+1] = x;
  22.     }
  23. }
  24.  
  25. void losuj_tablice(int* a, int n)
  26. {
  27.     for(int i = 0; i < n; i++)
  28.     {
  29.         a[i] = rand()%10 + 1;
  30.     }
  31. }
  32.  
  33. void wypisz(int *a , int n)
  34. {
  35.     for(int i = 0; i < n; i++)
  36.     {
  37.         std::cout << a[i] << " ";
  38.     }
  39.     std::cout << std::endl;
  40. }
  41.  
  42. int main()
  43. {
  44.     srand(time(NULL));
  45.    
  46.     const int n = 10;
  47.     int a[n];
  48.    
  49.     losuj_tablice(a,n);
  50.    
  51.     wypisz(a,n);   
  52.     prostew(a,n);
  53.     wypisz(a,n);
  54.    
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement