Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #include "functions.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. /// Problem 2
  6. int** fill_array(int** arr, unsigned n) {
  7.  
  8. for (int i = 0; i < 2; i++) {
  9. for (int j = 0; j < n; j++) {
  10. cin >> arr[i][j];
  11. }
  12. }
  13. return arr;
  14. }
  15.  
  16. /// Problem 3
  17. bool inj_check(int** arr, unsigned n) {
  18.  
  19. bool inj_check = false;
  20.  
  21. for (int i = 0; i < n; i++) {
  22. for (int j = i + 1; i < n; j++) {
  23. if (arr[0][i] != arr[0][j]) {
  24. if (arr[1][i] != arr[1][j]) {
  25. inj_check = true;
  26. }
  27. else {
  28. inj_check = false;
  29. break;
  30. }
  31. }
  32. }
  33. if (inj_check == false) {
  34. break;
  35. }
  36. if (inj_check == true) {
  37. cout << "Your array is injective.\n";
  38. return true;
  39. }
  40. else {
  41. cout << "Your array is not injective.\n";
  42. return false;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. /// Problem 4 tuka imam podchertana skobra sled func skobata (predi { - za tqloto na funkciqta), ako sloja ; iska na vsqka dolna funkciq da sloja ; na sushtoto mqsto
  49.  
  50.  
  51. bool surj_check(int** arr, unsigned n) {
  52.  
  53. bool surj_check = false;
  54.  
  55. for (int i = 0; i < n; i++) {
  56. for (int j = 0; j < n; j++) {
  57. if (arr[1][i] == arr[0][j]) {
  58. surj_check = true;
  59. }
  60. }
  61. }
  62. if (surj_check == 1) {
  63. cout << "Your array is surjecive.\n";
  64. return true;
  65. }
  66. else {
  67. cout << "Your array is not surjective.\n";
  68. return false;
  69. }
  70. }
  71.  
  72.  
  73. /// Problem 5
  74. bool bij_check(int** arr, unsigned n){
  75.  
  76. bool flag = true;
  77.  
  78. for (int i = 0; i < n; i++) {
  79. for (int k = i + 1; k < n; k++) {
  80. if (arr[i] == arr[k]) {
  81. flag = false;
  82. break;
  83. }
  84. }
  85. }
  86.  
  87. return flag;
  88. }
  89.  
  90. /// Problem 6
  91.  
  92. unsigned perm_count(int* arr, unsigned n) {
  93.  
  94. if (n == 0) return 1;
  95. return n * perm_count(arr, n - 1);
  96. }
  97.  
  98. /// Problem 7
  99.  
  100. bool fix_point_check(int** arr, unsigned n)
  101. {
  102. bool found_point = false;
  103.  
  104. for (int i = 0; i < n; i++) {
  105. if (arr[0][i] == arr[1][i]) {
  106. found_point = true;
  107. break;
  108. }
  109. }
  110. return found_point;
  111. }
  112.  
  113.  
  114. /// Problem 8
  115. unsigned fix_point_count(int** arr, unsigned n) {
  116.  
  117. unsigned count = 0;
  118.  
  119. for (int i = 0; i < n; i++) {
  120. if (arr[0][i] == arr[1][i]) count++;
  121. }
  122. return count;
  123. }
  124.  
  125. /// Problem 9
  126. bool ident_check(int** arr, unsigned n) {
  127.  
  128. int count = 0;
  129.  
  130. for (int i = 0; i < n; i++) {
  131. if (arr[0][i] == arr[1][i]) {
  132. count++;
  133. }
  134. }
  135. if (count == n) return true;
  136. else return false;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement