Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- void unos(int niz[], int);
- void spremi(int glavni_niz[], int niz1[], int niz2[], int);
- void ispis(int niz[], int);
- void sortiraj(int niz[], int);
- int main()
- {
- const int max = 5;
- int niz1[max];
- int niz2[max];
- unos(niz1, max);
- unos(niz2, max);
- const int max2 = 10;
- int niz3[max2];
- spremi(niz3, niz1, niz2, max2);
- ispis(niz3, max2);
- sortiraj(niz3,max2);
- ispis(niz3, max2);
- system("pause>null");
- return 0;
- }
- void unos(int niz[], int max)
- {
- cout << "Unesite vrijednosti niza: " << endl;
- for (int i = 0; i < max; i++)
- {
- cout << i + 1 << " -> ";
- cin >> niz[i];
- }
- cout << endl;
- }
- void spremi(int glavni_niz[], int niz1[], int niz2[], int max)
- {
- for (int i = 0; i < max/2; i++)
- {
- glavni_niz[i] = niz1[i];
- glavni_niz[i + 5] = niz2[i];
- }
- }
- void ispis(int niz [], int max)
- {
- cout << "Vas niz je: " << endl;
- for (int i = 0; i < max; i++)
- {
- cout << setw(3) << niz[i];
- }
- cout << endl;
- }
- void sortiraj(int niz[], int max)
- {
- bool sortirano = true;
- int j = 0;
- int tmp;
- while (sortirano) {
- sortirano= false;
- j++;
- for (int i = 0; i < max - j; i++) {
- if (niz[i] > niz[i + 1]) {
- tmp = niz[i];
- niz[i] = niz[i + 1];
- niz[i + 1] = tmp;
- sortirano = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment