Advertisement
Guest User

twojaStara

a guest
Feb 26th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. // ConsoleApplication28.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <stdlib.h>
  7. #include <time.h>
  8.  
  9. using namespace std;
  10.  
  11. void add(int* tab1,int* tab2, int r)
  12. {
  13. for (int a = 0; a < r; a++)
  14. {
  15. tab1[a] += tab2[a];
  16. }
  17. }
  18. void printTab(int* tab, int r)
  19. {
  20. cout << "\n\nSuma tablic:\n";
  21. for (int a = 0; a < r; a++)
  22. {
  23. cout << tab[a] << " ";
  24. }
  25. cout << "\n";
  26. }
  27. int main()
  28. {
  29. int min, max, a, r;
  30. cout << "Podaj rozmiar tablic\n";
  31. cin >> r;
  32. int * tab = new int[r];
  33. int * tab2 = new int[r];
  34.  
  35. cout << "Podaj zakres losowania liczb dla pierwszej tablicy\n";
  36. cin >> min >> max;
  37. srand(time(0));
  38. cout << "Pierwsza tablica\n\n";
  39. for (a = 0; a < r; a++)
  40. {
  41. tab[a] = min + rand() % (max - min + 1);
  42. cout << tab[a] << " ";
  43. }
  44. cout << "\n\nPodaj zakres losowania liczb dla drugiej tablicy\n";
  45. cin >> min >> max;
  46. cout << "Druga tablica\n\n";
  47. for (a = 0; a < r; a++)
  48. {
  49. tab2[a] = min + rand() % (max - min + 1);
  50. cout << tab2[a] << " ";
  51. }
  52. add(tab, tab2, r);
  53. printTab(tab, r);
  54. delete[] tab;
  55. delete[] tab2;
  56. system("pause");
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement