3 Starsenns

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

//STARSENNS

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
clock_t start=clock();
int A[2][2],B[2][2],C[2][2];
printf("THE ORDER OF THE MATRIX TAKEN IS 2x2\n");
printf("\nENTER ELEMENTS IN THE FIRST MATRIX\n");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
scanf("%d",&A[i][j]);
}
printf("\nENTER ELEMENTS IN THE SECOND MATRIX\n");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
scanf("%d",&B[i][j]);
}
int P1,P2,P3,P4,P5,P6,P7;
P1=(A[0][0]+A[1][1])*(B[0][0]+B[1][1]);
P2=(A[1][0]+A[1][1])*B[0][0];
P3=A[0][0]*(B[0][1]-B[1][1]);
P4=A[1][1]*(B[1][0]-B[0][0]);
P5=(A[0][0]+A[0][1])*B[1][1];
P6=(A[1][0]-A[0][0])*(B[0][0]+B[0][1]);
P7=(A[0][1]-A[1][1])*(B[1][0]+B[1][1]);

C[0][0]=P1+P4-P5+P7;
C[0][1]=P3+P5;
C[1][0]=P2+P4;
C[1][1]=P1+P3-P2+P6;

printf("THE FIRST MATRIX IS\n");


for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
printf("%d\t",A[i][j]);
printf("\n");
}
printf("\nTHE SECOND MATRIX IS\n");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
printf("%d\t",B[i][j]);
printf("\n");
}
printf("\nTHE RESULTANT MATRIX IS\n");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
printf("%d\t",C[i][j]);
printf("\n");
}
clock_t end=clock();
float time1=(float)(end-start)/CLOCKS_PER_SEC;
printf("THE TOTAL CPU TIME TAKE IS = %f Sec(s)\n",time1);
}

Algorithm: Matrix-Multiplication (X, Y, Z)


for i = 1 to p do
for j = 1 to r do
Z[i,j] := 0
for k = 1 to q do
Z[i,j] := Z[i,j] + X[i,k] × Y[k,j]

Complexity
Here, we assume that integer operations take O(1) time. There are three for loops
in this algorithm and one is nested in other. Hence, the algorithm takes O(n3) time
to execute.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy