Advertisement
dark-Matter

maakichut

Feb 27th, 2021
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. int MAX = 100;
  7. int n;
  8.  
  9. void print_array(int **a) {
  10.     for (int i = 0; i < n; i++)
  11.     {
  12.         for (int j = 0; j < n; j++)
  13.         {
  14.             cout << a[i][j] << " ";
  15.         }
  16.         cout << endl;
  17.     }
  18.    
  19. }
  20.  
  21. double job( int n)
  22. {
  23.     int **a, **b, **c;
  24.     a = (int**)malloc(n*sizeof(int*));
  25.     b = (int**)malloc(n*sizeof(int*));
  26.     c = (int**)malloc(n*sizeof(int*));
  27.     for (int i = 0; i < n; i++)
  28.     {
  29.         int *x = (int*)malloc(n*sizeof(int));
  30.         for (int j = 0; j < n; j++)
  31.         {
  32.             x[j] = rand()%100;
  33.         }
  34.         a[i] = x;
  35.     }
  36.  
  37.     for (int i = 0; i < n; i++)
  38.     {
  39.         int *x = (int*)malloc(n*sizeof(int));
  40.         int *y = (int*)malloc(n*sizeof(int));
  41.         for (int j = 0; j < n; j++)
  42.         {
  43.             x[j] = rand()%100;
  44.             y[j] = rand()%100;
  45.         }
  46.         b[i] = x;
  47.         c[i] = y;
  48.     }
  49.    
  50.    // print_array(a);
  51.    // print_array(b);
  52.     clock_t tic = clock();
  53.     for (int i = 0; i < n; i++)
  54.     {
  55.         for (int j = 0; j < n; j++)
  56.         {
  57.             c[i][j]=0;
  58.             for (int k = 0; k < n; k++)
  59.             {
  60.                 c[i][j] += a[i][k]*b[k][j];
  61.             }
  62.            
  63.         }
  64.     }
  65.     clock_t tac = clock();
  66.     //printf("Elapsed: %f seconds\n", (double)(tac - tic) / CLOCKS_PER_SEC);
  67.     //print_array(c);
  68.  
  69.     return (double)(tac - tic) / CLOCKS_PER_SEC;
  70. }
  71.  
  72. int main()
  73. {
  74.     for (int i = 1; i < 55; i++)
  75.     {
  76.         cout << "n : " << i*i << ", time :" << job(i*i) << endl;
  77.     }
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement