- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program for subtracting two matrices.
To subtract two matrices −
- Create an empty matrix.
- At each position in the new matrix, assign the difference of the values in the same position of the given two matrices i.e. if A[i][j] and B[i][j] are the two given matrices then, the value of c[i][j] should be A[i][j] - B[i][j].
Example
public class SubtractingMatrices{ public static void main(String args[]){ int a[][]={{1,2,3},{4,5,6},{7,8,9}}; int b[][]={{1,1,1},{1,1,1},{1,1,1}}; int c[][]=new int[3][3]; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ c[i][j] = a[i][j]-b[i][j]; System.out.print(c[i][j]+" "); } System.out.println(); } } }
Output
0 1 2 3 4 5 6 7 8
- Related Articles
- C# program to multiply two matrices
- Java program to add two matrices.
- Java program to subtract two matrices.
- Java program to multiply two matrices.
- C# program to add two matrices
- Python program to multiply two matrices
- Golang Program To Add Two Matrices
- C Program for subtraction of matrices
- Program to multiply two matrices in C++
- C++ Program to Check Multiplicability of Two Matrices
- How to write Java program to add two matrices
- C# program to check if two matrices are identical
- Subtracting two numbers without using the (-) sign JavaScript
- Java program to check if two given matrices are identical
- Python Program to check if two given matrices are identical

Advertisements