Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "functions.h"
- #include <iostream>
- using namespace std;
- /// Problem 2
- int** fill_array(int** arr, unsigned n) {
- for (int i = 0; i < 2; i++) {
- for (int j = 0; j < n; j++) {
- cin >> arr[i][j];
- }
- }
- return arr;
- }
- /// Problem 3
- bool inj_check(int** arr, unsigned n) {
- bool inj_check = false;
- for (int i = 0; i < n; i++) {
- for (int j = i + 1; i < n; j++) {
- if (arr[0][i] != arr[0][j]) {
- if (arr[1][i] != arr[1][j]) {
- inj_check = true;
- }
- else {
- inj_check = false;
- break;
- }
- }
- }
- if (inj_check == false) {
- break;
- }
- if (inj_check == true) {
- cout << "Your array is injective.\n";
- return true;
- }
- else {
- cout << "Your array is not injective.\n";
- return false;
- }
- }
- /// 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
- bool surj_check(int** arr, unsigned n) {
- bool surj_check = false;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (arr[1][i] == arr[0][j]) {
- surj_check = true;
- }
- }
- }
- if (surj_check == 1) {
- cout << "Your array is surjecive.\n";
- return true;
- }
- else {
- cout << "Your array is not surjective.\n";
- return false;
- }
- }
- /// Problem 5
- bool bij_check(int** arr, unsigned n){
- bool flag = true;
- for (int i = 0; i < n; i++) {
- for (int k = i + 1; k < n; k++) {
- if (arr[i] == arr[k]) {
- flag = false;
- break;
- }
- }
- }
- return flag;
- }
- /// Problem 6
- unsigned perm_count(int* arr, unsigned n) {
- if (n == 0) return 1;
- return n * perm_count(arr, n - 1);
- }
- /// Problem 7
- bool fix_point_check(int** arr, unsigned n)
- {
- bool found_point = false;
- for (int i = 0; i < n; i++) {
- if (arr[0][i] == arr[1][i]) {
- found_point = true;
- break;
- }
- }
- return found_point;
- }
- /// Problem 8
- unsigned fix_point_count(int** arr, unsigned n) {
- unsigned count = 0;
- for (int i = 0; i < n; i++) {
- if (arr[0][i] == arr[1][i]) count++;
- }
- return count;
- }
- /// Problem 9
- bool ident_check(int** arr, unsigned n) {
- int count = 0;
- for (int i = 0; i < n; i++) {
- if (arr[0][i] == arr[1][i]) {
- count++;
- }
- }
- if (count == n) return true;
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement