MeehoweCK

Untitled

Mar 15th, 2021
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. // zadanie 7.
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int* utworz(const unsigned n)
  9. {
  10.     int* tablica = new int[n];
  11.     for(unsigned i = 0; i < n; ++i)
  12.         tablica[i] = rand() % 101;
  13.     return tablica;
  14. }
  15.  
  16. int* suma(const int* t1, const int* t2, const unsigned n)
  17. {
  18.     int* nowa = new int[n];
  19.     for(unsigned i = 0; i < n; ++i)
  20.         nowa[i] = t1[i] + t2[i];
  21.     return nowa;
  22. }
  23.  
  24. void wypisz(const int* tab, const unsigned n)
  25. {
  26.     for(unsigned i = 0; i < n; ++i)
  27.         cout << tab[i] << '\t';
  28.     cout << endl;
  29. }
  30.  
  31. int main()
  32. {
  33.     srand(time(nullptr));
  34.     unsigned n;
  35.     cout << "Podaj wielkosc tablicy: ";
  36.     cin >> n;
  37.  
  38.     int* t1 = utworz(n);
  39.     int* t2 = utworz(n);
  40.     int* nowa_tablica = suma(t1, t2, n);
  41.     wypisz(t1, n);
  42.     wypisz(t2, n);
  43.     wypisz(nowa_tablica, n);
  44.  
  45.     delete[] t1;
  46.     delete[] t2;
  47.     delete[] nowa_tablica;
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment