Q:

Java - Matrix Manipulation (Addition, Subtraction, Multiplication)

0

This Program is used to calculate Matrix Manipulation such that Addition, Subtraction,Multiplication.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

class mat 
{ 
public static void main(String arg[]) 
{ 
int a[][] = {{1,2},{3,4}}; 
int b[][] = {{1,2},{3,4}}; 

int c[][] = new int[2][2]; 

int i,j,k; 

System.out.println("\nGiven A Matrix is..."); 
for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
System.out.print(a[i][j]+"\t"); 
} 
System.out.println("\n"); 
} 

System.out.println("\nGiven B Matrix is..."); 
for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
System.out.print(b[i][j]+"\t"); 
} 
System.out.println("\n"); 
} 


for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
c[i][j] = a[i][j] + b[i][j]; 
} 
} 

System.out.println("\nMatrix Addition is..."); 
for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
System.out.print(c[i][j]+"\t"); 
} 
System.out.println("\n"); 
} 

for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
c[i][j] = a[i][j] - b[i][j]; 
} 
} 

System.out.println("\nMatrix Subtraction is..."); 
for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
System.out.print(c[i][j]+"\t"); 
} 
System.out.println("\n"); 
} 

for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
for(k=0;k<2;k++) 
{ 
c[i][j] = c[i][j] + a[i][k] * b[k][j]; 
} 
} 
} 

System.out.println("\nMatrix Multiplication is..."); 
for(i=0;i<2;i++) 
{ 
for(j=0;j<2;j++) 
{ 
System.out.print(c[i][j]+"\t"); 
} 
System.out.println("\n"); 
} 

} 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now