Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. void unos(int niz[], int vel)
  6. {
  7. for (int i = 0; i < vel; i++)
  8. {
  9. cin >> niz[i];
  10. }
  11. }
  12.  
  13. int min(int a, int b)
  14. {
  15. if (a<b)
  16. {
  17. return a;
  18. }
  19. return b;
  20. }
  21.  
  22. void inicijalizacija(int niz1[], int niz2[], int niz3[], int vel)
  23. {
  24. for (int i = 0; i < vel; i++)
  25. {
  26. niz3[i] = min(niz1[i], niz2[i]);
  27. }
  28. }
  29.  
  30. bool opadajuci(int niz[], int vel)
  31. {
  32. for (int i = 0; i < vel; i++)
  33. {
  34. if (niz[i] < niz[i + 1])
  35. {
  36. return false;
  37. }
  38. }
  39. return true;
  40. }
  41.  
  42. void ispis(int niz[], int vel)
  43. {
  44. for (int i = 0; i < vel; i++)
  45. {
  46. cout << niz[i] << " ";
  47. }
  48. cout << endl;
  49. }
  50.  
  51. void main()
  52. {
  53. const int vel = 5;
  54. int niz1[vel];
  55. int niz2[vel];
  56. int niz3[vel];
  57.  
  58. unos(niz1, vel);
  59. unos(niz2, vel);
  60.  
  61. inicijalizacija(niz1, niz2, niz3, vel);
  62.  
  63. ispis(niz1, vel);
  64. ispis(niz2, vel);
  65. ispis(niz3, vel);
  66.  
  67. int izbor;
  68. cout << "Izaberite niz za koji zelite provjeriti da li su mu elementi u opadajucem poretku:" << endl;
  69. cout << "Izaberite: 1, 2 ili 3" << endl;
  70. cin >> izbor;
  71.  
  72. if (izbor == 1)
  73. {
  74. if (opadajuci(niz1, vel) == true)
  75. {
  76. cout << "Niz je opadajuci!" << endl;
  77. }
  78. else
  79. cout << "Niz nije opadajuci!" << endl;
  80. }
  81. if (izbor == 2)
  82. {
  83. if (opadajuci(niz2, vel) == true)
  84. {
  85. cout << "Niz je opadajuci!" << endl;
  86. }
  87. else
  88. cout << "Niz nije opadajuci!" << endl;
  89. }
  90. if (izbor == 3)
  91. {
  92. if (opadajuci(niz3, vel) == true)
  93. {
  94. cout << "Niz je opadajuci!" << endl;
  95. }
  96. else
  97. cout << "Niz nije opadajuci!" << endl;
  98. }
  99.  
  100. system("pause>0");
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement