Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int MAX = 100;
- int n;
- void print_array(int **a) {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- double job( int n)
- {
- int **a, **b, **c;
- a = (int**)malloc(n*sizeof(int*));
- b = (int**)malloc(n*sizeof(int*));
- c = (int**)malloc(n*sizeof(int*));
- for (int i = 0; i < n; i++)
- {
- int *x = (int*)malloc(n*sizeof(int));
- for (int j = 0; j < n; j++)
- {
- x[j] = rand()%100;
- }
- a[i] = x;
- }
- for (int i = 0; i < n; i++)
- {
- int *x = (int*)malloc(n*sizeof(int));
- int *y = (int*)malloc(n*sizeof(int));
- for (int j = 0; j < n; j++)
- {
- x[j] = rand()%100;
- y[j] = rand()%100;
- }
- b[i] = x;
- c[i] = y;
- }
- // print_array(a);
- // print_array(b);
- clock_t tic = clock();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- c[i][j]=0;
- for (int k = 0; k < n; k++)
- {
- c[i][j] += a[i][k]*b[k][j];
- }
- }
- }
- clock_t tac = clock();
- //printf("Elapsed: %f seconds\n", (double)(tac - tic) / CLOCKS_PER_SEC);
- //print_array(c);
- return (double)(tac - tic) / CLOCKS_PER_SEC;
- }
- int main()
- {
- for (int i = 1; i < 55; i++){
- cout << "n : " << i*i << ", time :" << job(i*i) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement