matrix substraction

Ads
 

matrix substraction

hai

View Answers

January 20, 2011 at 11:37 AM

Hi Friend,

Try this:

import java.util.*;
class MatrixSubtraction{

    public static void main(String[] args){
     Scanner input = new Scanner(System.in);
    int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++)
for  (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i=0 ; i < B.length ; i++)
for  (int j=0 ; j < B[i].length ; j++){
B[i][j] = input.nextInt();
}
System.out.println("Matrix A: ");
        for (int i=0 ; i < A.length ; i++){
            System.out.println();
            for  (int j=0 ; j < A[i].length ; j++){
                System.out.print(A[i][j]+" ");
                  }
        }
System.out.println();
System.out.println();
System.out.println("Matrix B: ");
        for (int i=0 ; i < B.length ; i++){    
            System.out.println();
            for  (int j=0 ; j < B[i].length ; j++){
                System.out.print(B[i][j]+" ");
                  }
        }
System.out.println();
System.out.println();
System.out.println("Subtraction Of Matrices: ");
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();
}
}
}

Thanks

Ads









Related Tutorials/Questions & Answers:
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
Advertisements
matrix addition
matrix addition  hai
matrix addition
matrix addition  hai
matrix adddition
matrix adddition   how to write a program matrix addition in java
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
transpose matrix
integers into the matrix and print the transpose of it. for this program u r given answer but if i entered 2 by 3 matrix it will not give answer ple check it once
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
transpose of matrix
transpose of matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose
matrix determination in java
matrix determination in java  hai
matrix polynamial addtion
matrix polynamial addtion  hai
matrix
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
ModuleNotFoundError: No module named 'matrix'
ModuleNotFoundError: No module named 'matrix'  Hi, My Python... 'matrix' How to remove the ModuleNotFoundError: No module named 'matrix'... to install padas library. You can install matrix python with following command
ModuleNotFoundError: No module named 'the-matrix'
ModuleNotFoundError: No module named 'the-matrix'  Hi, My Python... 'the-matrix' How to remove the ModuleNotFoundError: No module named 'the-matrix' error? Thanks   Hi, In your python environment you
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
parallel dense matrix multiplication
parallel dense matrix multiplication  hi friends, i am a final year... using dense parallel matrix multiplication. I request you to kindly provide me a code for Parallel Matrix multiplication on distributed systems using Java
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
Javascript matrix error
Javascript matrix error  This function blows up (without an error) whenever it is called function valid(n){ //n is a number 0-9 if(board...; } } where board is a global 3x3 Array matrix var board = new Array(3
TensorFlow placeholder matrix
matrix with TensorFlow? I am searching for TensorFlow placeholder matrix... matrix and it can easily perform various operations on the matrix. In the following example we are defining a multi-dimensional matrix as placeholder
ModuleNotFoundError: No module named 'confusion-matrix'
ModuleNotFoundError: No module named 'confusion-matrix'  Hi, My... named 'confusion-matrix' How to remove the ModuleNotFoundError: No module named 'confusion-matrix' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'matrix-calculator'
ModuleNotFoundError: No module named 'matrix-calculator'  Hi, My... named 'matrix-calculator' How to remove the ModuleNotFoundError: No module named 'matrix-calculator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'matrix-completion'
ModuleNotFoundError: No module named 'matrix-completion'  Hi, My... named 'matrix-completion' How to remove the ModuleNotFoundError: No module named 'matrix-completion' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'matrix-lite'
ModuleNotFoundError: No module named 'matrix-lite'  Hi, My Python... 'matrix-lite' How to remove the ModuleNotFoundError: No module named 'matrix-lite' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'matrix-mania'
ModuleNotFoundError: No module named 'matrix-mania'  Hi, My Python... 'matrix-mania' How to remove the ModuleNotFoundError: No module named 'matrix-mania' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'matrix-ops'
ModuleNotFoundError: No module named 'matrix-ops'  Hi, My Python... 'matrix-ops' How to remove the ModuleNotFoundError: No module named 'matrix-ops' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'matrix-pybot'
ModuleNotFoundError: No module named 'matrix-pybot'  Hi, My Python... 'matrix-pybot' How to remove the ModuleNotFoundError: No module named 'matrix-pybot' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'matrix-sydent'
ModuleNotFoundError: No module named 'matrix-sydent'  Hi, My... 'matrix-sydent' How to remove the ModuleNotFoundError: No module named 'matrix-sydent' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pedigree_matrix'
ModuleNotFoundError: No module named 'pedigree_matrix'  Hi, My... named 'pedigree_matrix' How to remove the ModuleNotFoundError: No module named 'pedigree_matrix' error? Thanks   Hi, In your python

Ads