Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. #include<iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. void create(int* x, int n)
  5. {
  6.     cout << "Введите значения членов вектора"<<endl;
  7.     for (int i = 0; i < n; i++)
  8.     {
  9.         cout << "z[" << i << "]=";
  10.         cin >> x[i];
  11.     }
  12. }
  13.  
  14. void show(int* x, int n)
  15. {
  16.     for (int i = 0; i < n; i++)
  17.     {
  18.         cout << x[i]<<' ';
  19.     }
  20. }
  21.  
  22. int maximum(int* x, int n)
  23. {
  24.     int max=1;
  25.     for (int i = 0; i < n; i++)
  26.     {
  27.         if(max<x[i] || max==1)
  28.         {
  29.             max = x[i];
  30.         }
  31.        
  32.     }
  33.     return max;
  34. }
  35. void create_matr(int** x, int n)
  36. {
  37.    
  38.    
  39.     for ( int i = 0; i < n; i++)
  40.     {
  41.         for ( int j = 0; j < n; j++)
  42.         {
  43.             cout <<"[" << i << "][" << j << "]= ";
  44.             cin >> x[i][j];
  45.         }
  46.     }
  47. }
  48.  
  49. void show_matr(int** x, int n)
  50. {
  51.    
  52.     for (int i = 0; i < n; i++)
  53.     {
  54.         for (int j = 0; j < n; j++)
  55.             cout <<setw(5)<< x[i][j];
  56.         cout << endl;
  57.     }
  58. }
  59.  
  60. void umnozhenie(int** d, int* b, int* c, int n)
  61. {  
  62.     int i, j;
  63.     for (i = 0; i < n; i++)
  64.     {
  65.         c[i] = 0;
  66.         for (j = 0; j < n; j++)
  67.         {
  68.             c[i] += (d[i][j] * b[j]);
  69.         }
  70.        
  71.     }
  72. }
  73.  
  74.  
  75. int main()
  76. {
  77.     setlocale(LC_ALL,"Rus");
  78.     int n;
  79.     cout << "Введите размер вектора и матрицы: ";
  80.     cin >> n;
  81.     int* z = new int[n];
  82.     create(z, n);
  83.     show(z, n);
  84.     cout << endl;
  85.     cout << "максимальное значение ="<<maximum(z, n)<<endl;
  86.     int** matr_a = new int* [n];
  87.     int i;
  88.     for (i = 0; i < n; i++)
  89.         matr_a[i] = new int[n];
  90.     cout << "Введите значения членов матрицы А "<< endl;
  91.     create_matr(matr_a, n);
  92.     cout << "Матрица А: "<< endl;
  93.     show_matr(matr_a, n);
  94.  
  95.     int** matr_b = new int* [n];
  96.     for (i = 0; i < n; i++)
  97.         matr_b[i] = new int[n];
  98.     cout << "Введите значения членов матрицы B " << endl;
  99.     create_matr(matr_b, n);
  100.     cout << "Матрица B: " << endl;
  101.     show_matr(matr_b, n);
  102.  
  103.     cout << "Введите число C=";
  104.     double c;
  105.     cin >>c;
  106.    
  107.     int* y=new int[n];
  108.    
  109.    
  110.     for (i = 0; i < 5; i++)
  111.     {
  112.         if (maximum(z, n) > c)
  113.             umnozhenie(matr_a, z, y, n);
  114.         else umnozhenie(matr_b, z, y, n);
  115.         for (int j = 0; j < n; j++)
  116.                     z[j] = y[j];
  117.        
  118.  
  119.     }
  120.     cout << "Вектор У:" << endl;
  121.     show(y, n);
  122.        
  123.     delete[] z;
  124.     for (i = 0; i < n; i++)
  125.     {
  126.         delete[] matr_a[i];
  127.         delete[] matr_b[i];
  128.     }
  129.     delete[] matr_a;
  130.     delete[] matr_b;
  131.     delete[] y;
  132.         return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement