Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // zadanie 7.
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int* utworz(const unsigned n)
- {
- int* tablica = new int[n];
- for(unsigned i = 0; i < n; ++i)
- tablica[i] = rand() % 101;
- return tablica;
- }
- int* suma(const int* t1, const int* t2, const unsigned n)
- {
- int* nowa = new int[n];
- for(unsigned i = 0; i < n; ++i)
- nowa[i] = t1[i] + t2[i];
- return nowa;
- }
- void wypisz(const int* tab, const unsigned n)
- {
- for(unsigned i = 0; i < n; ++i)
- cout << tab[i] << '\t';
- cout << endl;
- }
- int main()
- {
- srand(time(nullptr));
- unsigned n;
- cout << "Podaj wielkosc tablicy: ";
- cin >> n;
- int* t1 = utworz(n);
- int* t2 = utworz(n);
- int* nowa_tablica = suma(t1, t2, n);
- wypisz(t1, n);
- wypisz(t2, n);
- wypisz(nowa_tablica, n);
- delete[] t1;
- delete[] t2;
- delete[] nowa_tablica;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment