Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<time.h>
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #define M 8
  6. #define N 10
  7. using namespace std;
  8.  
  9. void generujMaticuNahodne(int matica[M][N], int m, int n);
  10. void vypisMaticu(int matica[M][N], int m, int n);
  11. void minusujRiadok(int matica[M][N], int m, int n, unsigned short R);
  12. void vynasob2Obvod(int matica[M][N], int m, int n);
  13. void odpocitajStlpecOdStlpca(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2);
  14. unsigned short pocetRovnakychPrvkovVStlpcoch(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2);
  15. bool obsahujeRiadokNeparneCislo(int matica[M][N], int m, int n, unsigned short R);
  16.  
  17. int main()
  18. {
  19. int m = 8;
  20. int n = 10;
  21. unsigned short R1, R2, S1, S2, S3, S4;
  22. int MATICA[M][N];
  23. generujMaticuNahodne(MATICA, m, n);
  24. vypisMaticu(MATICA, m, n);
  25. cout << "Zadaj index riadku " << endl;
  26. cin >> R1;
  27. minusujRiadok(MATICA, m, n, R1);
  28. vypisMaticu(MATICA, m, n);
  29. cout << endl;
  30. vynasob2Obvod(MATICA, m, n);
  31. vypisMaticu(MATICA, m, n);
  32. cout << "Zadaj prvy stlpec ";
  33. cin >> S1;
  34. cout << "Zadaj druhy stlpec ";
  35. cin >> S2;
  36. odpocitajStlpecOdStlpca(MATICA, m, n, S1, S2);
  37. vypisMaticu(MATICA, m, n);
  38. cout << "Zadaj prvy stlpec ";
  39. cin >> S3;
  40. cout << "Zadaj druhy stlpec ";
  41. cin >> S4;
  42. cout << "Pocet rovnakych prvkov v zadanych stlpcoch je : " << pocetRovnakychPrvkovVStlpcoch(MATICA, m, n, S3, S4) << endl;
  43. cout << "Zadaj index riadku : ";
  44. cin >> R2;
  45. if (obsahujeRiadokNeparneCislo(MATICA, m, n, R2))
  46. {
  47. cout << "Riadok obsahuje neparne cislo" << endl;
  48. }
  49. else
  50. cout << "neobsahuje neparne cislo" << endl;
  51.  
  52.  
  53.  
  54. system("pause");
  55. return 0;
  56. }
  57.  
  58.  
  59. void generujMaticuNahodne(int matica[M][N], int m, int n)
  60. {
  61. for (int i = 0; i < m; i++)
  62. {
  63. for (int j = 0; j < n; j++)
  64. {
  65. matica[i][j] = -30 + (rand() % (-10 - (-30) + 1));
  66. }
  67. }
  68. }
  69.  
  70. void vypisMaticu(int matica[M][N], int m, int n)
  71. {
  72. for (int i = 0; i < m; i++)
  73. {
  74. for (int j = 0; j < n; j++)
  75. {
  76. cout << matica[i][j] << "\t";
  77. }
  78. cout << endl;
  79. }
  80. }
  81.  
  82. void minusujRiadok(int matica[M][N], int m, int n, unsigned short R)
  83. {
  84. for (int i = 0; i < m; i++)
  85. {
  86. for (int j = 0; j < n; j++)
  87. {
  88. if (i == R-1)
  89. {
  90. matica[i][j] *= -1;
  91. }
  92. }
  93. }
  94. }
  95.  
  96. void vynasob2Obvod(int matica[M][N], int m, int n)
  97. {
  98. for (int i = 0; i < m; i++)
  99. {
  100. for (int j = 0; j < n; j++)
  101. {
  102. if (i == 0 || i == m - 1 || j == 0 || j == n - 1)
  103. matica[i][j] = matica[i][j] * 2;
  104. }
  105. }
  106. }
  107.  
  108. void odpocitajStlpecOdStlpca(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2)
  109. {
  110. for (int i = 0; i < m; i++)
  111. {
  112. for (int j = 0; j < n; j++)
  113. {
  114. if (j == S1)
  115. {
  116. matica[i][S2] -= matica[i][S1];
  117. }
  118.  
  119. }
  120. }
  121. }
  122.  
  123. unsigned short pocetRovnakychPrvkovVStlpcoch(int matica[M][N], int m, int n, unsigned short S1, unsigned short S2)
  124. {
  125. unsigned short pocetRovnakych = 0;
  126. for (int i = 0; i < m; i++)
  127. {
  128. if (matica[i][S1] == matica[i][S2])
  129. pocetRovnakych++;
  130. }
  131. return pocetRovnakych;
  132. }
  133.  
  134. bool obsahujeRiadokNeparneCislo(int matica[M][N], int m, int n, unsigned short R)
  135. {
  136. unsigned short neparne = 0;
  137. for (int i = 0; i < m; i++)
  138. {
  139.  
  140. for (int j = 0; j < n; j++)
  141. {
  142. if (i == R)
  143. {
  144. if (matica[R][j] % 2 == 1)
  145. neparne++;
  146. }
  147. }
  148. }
  149. if (neparne > 0) return true;
  150. else return false;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement