carrot385

XEP

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