Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "cmath"
- #include <iostream>
- #include <time.h>
- using namespace std;
- bool func(float a, float b, float c, float d, float S)
- {
- if ((a + b + c + d) < S) { return true; }
- else { return false; }
- }
- int main()
- {
- srand(time(NULL));
- int n, m;
- float S;
- cout << "Enter n and m" << endl;
- cin >> n >> m;
- cout << "Enter S" << endl;
- cin >> S;
- float **a = new float*[n];
- for (int i = 0; i < n; i++)
- a[i] = new float;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- a[i][j] = rand()%500;
- bool **b = new bool*[n];
- for (int i = 0; i < n; i++)
- b[i] = new bool;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- b[i][j] = false;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- if ((i == 0) || (i == (n - 1)) || (j == 0) || (j == (m - 1)))
- {
- if ((i == 0) && (j == 0)) { if ((a[i + 1][j] + a[i][j + 1]) < S) b[i][j] = true; }
- else if ((i == 0) && (j == (m - 1))) { if ((a[i + 1][j] + a[i][j - 1]) < S) b[i][j] = true; }
- else if ((i == (n - 1)) && (j == 0)) { if ((a[i - 1][j] + a[i][j + 1]) < S) b[i][j] = true; }
- else if ((i == (n - 1)) && (j == (m - 1))) { if ((a[i - 1][j] + a[i][j - 1]) < S) b[i][j] = true; }
- else if (i == 0) { if ((a[i + 1][j] + a[i][j - 1] + a[i][j + 1]) < S) b[i][j] = true; }
- else if (j == 0) { if ((a[i - 1][j] + a[i + 1][j] + a[i][j + 1]) < S) b[i][j] = true; }
- else if (i == (n - 1)) { if ((a[i - 1][j] + a[i][j - 1] + a[i][j + 1]) < S) b[i][j] = true; }
- else if (j == (m - 1)) { if ((a[i - 1][j] + a[i][j - 1] + a[i + 1][j]) < S) b[i][j] = true; }
- }
- else { b[i][j] = func(a[i - 1][j], a[i + 1][j], a[i][j - 1], a[i][j + 1], S); }
- cout << "Resulting array:" << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- cout << b[i][j] << " ";
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement