Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void create(int** a, int n, char p) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout << p << "[" << i << "][" << j << "]="; cin >> a[i][j];
- }
- }
- }
- bool check(int** a, int n) {
- bool E = false;
- for (int i = 0; i < n && !E; i++) {
- bool A = true;
- for (int j = 0; j < n && A; j++) {
- if (a[i][j] >= 0) { A = false; }
- }
- if (A) { E = true;}
- }
- return E;
- }
- void sum(int** a, int** b,int **c, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- c[i][j] = a[i][j] + b[i][j];
- }
- }
- }
- void mult(int** a, int** b, int** c, int n) {
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++) {
- c[i][j] = 0;
- for (int k = 0; k < n; k++)
- c[i][j] += a[i][k] * b[k][j];
- }
- }
- void show(int** a, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- cout << a[i][j] << " ";
- }
- cout << "\n";
- }
- }
- int main() {
- setlocale(LC_ALL, "Ru");
- int** a, ** b, ** c, n;
- cout << "Введите размер квадратных матриц:";
- cin >> n;
- a = new int* [n];
- b = new int* [n];
- c = new int* [n];
- for (int i = 0; i < n; i++) {
- a[i] = new int[n];
- b[i] = new int[n];
- c[i] = new int[n];
- }
- cout << "Заполните массив А:\n";
- create(a,n,'А');
- cout << "Заполните массив В:\n";
- create(b, n, 'В');
- cout << "Массив А:\n";
- show(a, n);
- cout << "Массив B:\n";
- show(b, n);
- if (check(a, n)) {
- cout << "Сумма:\n";
- sum(a, b, c, n);
- show(c, n);
- }
- else {
- cout << "Произведение:\n";
- mult(a, b, c, n);
- show(c, n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement