Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- void prostew(int* a, int n)
- {
- int i,j;
- int x;
- for(i = 1; i < n; i++)
- {
- x = a[i];
- j = i-1;
- while(x < a[j])
- {
- a[j+1] = a[j];
- j = j-1;
- }
- a[j+1] = x;
- }
- }
- void losuj_tablice(int* a, int n)
- {
- for(int i = 0; i < n; i++)
- {
- a[i] = rand()%10 + 1;
- }
- }
- void wypisz(int *a , int n)
- {
- for(int i = 0; i < n; i++)
- {
- std::cout << a[i] << " ";
- }
- std::cout << std::endl;
- }
- int main()
- {
- srand(time(NULL));
- const int n = 10;
- int a[n];
- losuj_tablice(a,n);
- wypisz(a,n);
- prostew(a,n);
- wypisz(a,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement