carrot385

хехехех

Sep 22nd, 2021
803
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double **matrix_input(int size, int matrix_id)
  2. {
  3.   double **matrix = new double *[size];
  4.   cout << "Input matrix " << matrix_id << " size of " << size << "x" << size << endl;
  5.   for(int i = 0; i < size; i++)
  6.   {
  7.     for(int j = 0; j< size; j++)
  8.     {
  9.       cin >> matrix[i][j];
  10.     }
  11.   }
  12.   return matrix;
  13. }
  14.  
  15. double matrix_calculate(double **matrix, int size)
  16. {
  17.   double multiply = 1;
  18.   for(int i = 0; i < size; i++)
  19.   {
  20.     for(int j = 0; j< size; j++)
  21.     {
  22.       if(i==j)
  23.       {
  24.         multiply*=matrix[i][j];
  25.       }
  26.     }
  27.     return multiply;
  28.   }
  29. }
  30. double calc(double mult1, double mult2, double mult3)
  31. {
  32.   return mult1+mult2-mult3;
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38.   double **matrix1 = matrix_input(5, 1);
  39.   double **matrix2 = matrix_input(7, 2);
  40.   double **matrix3 = matrix_input(4, 3);
  41.   double mult1, mult2, mult3;
  42.   mult1 = matrix_calculate(matrix1, 5);
  43.   mult2 = matrix_calculate(matrix2, 7);
  44.   mult3 = matrix_calculate(matrix3, 4);
  45.   double result = calc(mult1, mult2, mult3);
  46.   cout << result << endl;
  47.   return 0;
  48. }
RAW Paste Data