Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <iomanip>
- using namespace std;
- void create(int* x, int n)
- {
- cout << "Введите значения членов вектора"<<endl;
- for (int i = 0; i < n; i++)
- {
- cout << "z[" << i << "]=";
- cin >> x[i];
- }
- }
- void show(int* x, int n)
- {
- for (int i = 0; i < n; i++)
- {
- cout << x[i]<<' ';
- }
- }
- int maximum(int* x, int n)
- {
- int max=1;
- for (int i = 0; i < n; i++)
- {
- if(max<x[i] || max==1)
- {
- max = x[i];
- }
- }
- return max;
- }
- void create_matr(int** x, int n)
- {
- for ( int i = 0; i < n; i++)
- {
- for ( int j = 0; j < n; j++)
- {
- cout <<"[" << i << "][" << j << "]= ";
- cin >> x[i][j];
- }
- }
- }
- void show_matr(int** x, int n)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- cout <<setw(5)<< x[i][j];
- cout << endl;
- }
- }
- void umnozhenie(int** d, int* b, int* c, int n)
- {
- int i, j;
- for (i = 0; i < n; i++)
- {
- c[i] = 0;
- for (j = 0; j < n; j++)
- {
- c[i] += (d[i][j] * b[j]);
- }
- }
- }
- int main()
- {
- setlocale(LC_ALL,"Rus");
- int n;
- cout << "Введите размер вектора и матрицы: ";
- cin >> n;
- int* z = new int[n];
- create(z, n);
- show(z, n);
- cout << endl;
- cout << "максимальное значение ="<<maximum(z, n)<<endl;
- int** matr_a = new int* [n];
- int i;
- for (i = 0; i < n; i++)
- matr_a[i] = new int[n];
- cout << "Введите значения членов матрицы А "<< endl;
- create_matr(matr_a, n);
- cout << "Матрица А: "<< endl;
- show_matr(matr_a, n);
- int** matr_b = new int* [n];
- for (i = 0; i < n; i++)
- matr_b[i] = new int[n];
- cout << "Введите значения членов матрицы B " << endl;
- create_matr(matr_b, n);
- cout << "Матрица B: " << endl;
- show_matr(matr_b, n);
- cout << "Введите число C=";
- double c;
- cin >>c;
- int* y=new int[n];
- for (i = 0; i < 5; i++)
- {
- if (maximum(z, n) > c)
- umnozhenie(matr_a, z, y, n);
- else umnozhenie(matr_b, z, y, n);
- for (int j = 0; j < n; j++)
- z[j] = y[j];
- }
- cout << "Вектор У:" << endl;
- show(y, n);
- delete[] z;
- for (i = 0; i < n; i++)
- {
- delete[] matr_a[i];
- delete[] matr_b[i];
- }
- delete[] matr_a;
- delete[] matr_b;
- delete[] y;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement