3 Starsenns
3 Starsenns
3 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;
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.