Advertisement
WiktoriaRatajczyk

Zadanie11

Apr 16th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. void losuj(int *a, int *b, int n, int max)
  9. {
  10.     while(n--)
  11.     {
  12.         *a++ = rand()%(max+1);
  13.         *b++ = rand()%(max+1);
  14.     }
  15. }
  16.  
  17. void wyswietl(int n, int *tab)
  18. {
  19.     while(n--)
  20.     {
  21.         cout.width(4); //znalazlam "opcje" ktora pozwala na rownomierne ulozenie tego - widac dokladniej sumowanie tego w tablicy c
  22.         cout<<*tab++<<" ";
  23.     }
  24.         cout<<endl;
  25. }
  26.  
  27. int main()
  28. {
  29.     srand(time(0));
  30.     int a[10], b[10], c[10], max;
  31.     cout << "Wpisz max: ";
  32.     cin >> max;
  33.     losuj (a,b,10,max);
  34.     for(int i=0;i<10;++i)
  35.     {*(c+i) = *(a+i) + *(b+i);}
  36.  
  37.     wyswietl(10,a);
  38.     wyswietl(10,b);
  39.     wyswietl(10,c);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement