-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixint.C
More file actions
53 lines (47 loc) · 1.05 KB
/
Matrixint.C
File metadata and controls
53 lines (47 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int n;
scanf("%d", &n);
int Arr1[n][n];
int Arr2[n][n];
int Ans[n][n];
int joy;
for (int i =0; i<n; i++)
{
for (int j=0; j<n; j++)
{
Arr1[i][j] = rand()%10+1;
Arr2[i][j] = rand()%10+1;
}
}
struct timespec ts;
char buff[100];
timespec_get(&ts, TIME_UTC);
unsigned long long int start = ts.tv_nsec;
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
joy = 0;
for (int k =0; k<n; k++)
{
joy += Arr1[i][k]*Arr2[k][j];
}
Ans[i][j] = joy;
printf("%d\
", Ans[i][j]);
}
}
timespec_get(&ts, TIME_UTC);
unsigned long long int end = ts.tv_nsec;
strftime(buff, sizeof buff, "%D %T", gmtime(&ts.tv_sec));
unsigned long long int ans = (end-start);
printf("\n");
printf("Time elapsed: ");
printf("%lld", ans);
printf(" ns\n");
return 0;
}