Fork Liberary

You might also like

You are on page 1of 2

/*Headers files */

#include<time.h>
#include<stdlib.h>
#include<stdio.h>
/* length of the matrix */
#define N 1024
/* Array dec */

int C[N][N],A[N][N],B[N][N];

/* Array to fill rendemly */


void initialize(int T[][N])
{
int i, j;
for(i = 0 ; i < N ; i++)
{
for(j = 0 ; j < N ; j++)
{
T[i][j]=rand()%100;
}
}
/* print */
}
void print(int T[][N])
{
int i, j;
for(i = 0 ; i < N ; i++)
{
for(j = 0 ; j < N ; j++)
{
printf("%5d ",T[i][j]);
}
printf("\n");
}
}
/* Add matrix method */
void Add(int T[][N],int X[][N],int Y[][N])
{
int i, j;
for(i = 0 ; i < N ; i++)
{
for(j = 0 ; j < N ; j++)
{
T[i][j]=X[i][j]+Y[i][j];
}
}
}
/* sub matrix method */
void sub(int T[][N],int X[][N],int Y[][N])
{
int i, j;
for(i = 0 ; i < N ; i++)
{
for(j = 0 ; j < N ; j++)
{
T[i][j]=X[i][j]-Y[i][j];
}
}
}
/* Mul matrix method */
void multi(int T[][N],int X[][N],int Y[][N])
{
int i, j,k,sum;
for(i = 0 ; i < N ; i++)
{
for(j = 0 ; j < N ; j++)
{
for(k=0;k<N;k++)
{
sum = sum + X[i][j]*Y[i][j];
}
T[i][j]=sum;
sum=0;
}
}
}

int main(int agrc, char *argv[])


{
clock_t t;
/* random number generated through time */
srand(time(NULL));
/* adding number to array which we generated through srand */

initialize(A);
initialize(B);
/* for present time */
t = clock();
/* call add method */
Add(C,A,B);
/*for time calculation */
t = clock() - t;
double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
/* print to display what time it will take */
printf("TIME TO ADD TWO MATRIX OF SIZE %d IS= %f \n", N,time_taken);
/* call sub method */
sub(C,A,B);
/*for time calculation */
t = clock() - t;
time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
/* print to display what time it will take */
printf("TIME TO SUBTRACT TWO MATRIX OF SIZE %d IS= %f \n", N,time_taken);
/* call mul method */
multi(C,A,B);
/*for time calculation */
t = clock() - t;
time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds
/* print to display what time it will take */
printf("TIME TO MULTPLY TWO MATRIX OF SIZE %d IS= %f \n", N,time_taken);

printf("Exiting of the program...\n");

return 0;
}

You might also like