Advertisement
skioe

Матрицы, время исполнения, лаба 3-5

Oct 25th, 2021
1,239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <cmath>
  3. #include <iostream>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.     int M, N;
  11.     double string_sum, row_product, duration;
  12.  
  13.     cin >> M;
  14.     cin >> N;
  15.     row_product = 1;
  16.  
  17.     double** Matrix = new double* [M];
  18.  
  19.     for (int i = 1; i <= M; i++)
  20.     {
  21.         Matrix[i - 1] = new double[N];
  22.  
  23.         for (int j = 1; j <= N; j++)
  24.         {
  25.             Matrix[i - 1][j - 1] = sqrt(i + j);
  26.             //cout << Matrix[i - 1][j - 1] << "\t";
  27.         }
  28.  
  29.         //cout << endl;
  30.     }
  31.  
  32.     duration = clock();
  33.  
  34.     for (int i = 1; i <= M; i++)
  35.     {
  36.         string_sum = 0;
  37.  
  38.         for (int j = 1; j <= N; j++)
  39.         {
  40.             Matrix[i - 1][j - 1] = sqrt(i + j);
  41.             string_sum += Matrix[i - 1][j - 1];
  42.         }
  43.  
  44.         row_product *= string_sum;
  45.     }
  46.  
  47.     duration = clock() - duration;
  48.  
  49.     cout << "Total product - " << row_product << endl;
  50.     cout << "Time in ticks / secs - " << duration << " / " << duration / (double) CLOCKS_PER_SEC;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement