1. Write a java program to find the sum of the elements on the diagonal of a matrix.
2. Write a java program to add two matrices.
3. Write a java program to find a given value in a matrix.
4. Write a java program to multiply two matrices.
5. Write a java program to find the transpose of a matrix.
Ans. to Q1
Program ->
import java.util.*; class SumElementsDiagonal { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("\nEnter Number of rows of a Matrix: "); int rows=sc.nextInt(); System.out.print("\nEnter Number of columns of a Matrix: "); int cols=sc.nextInt(); int m1[][],m2[][]; m1=new int[rows][cols]; System.out.println("\nEnter Elements of Matrix- m1: \n"); for(int r=0;r
Ans. to Q2
Program ->
import java.util.*; class AddMatrices { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("\nEnter Number of rows of a Matrix: "); int rows=sc.nextInt(); System.out.print("\nEnter Number of columns of a Matrix: "); int cols=sc.nextInt(); int m1[][],m2[][],m3[][]; m1=new int[rows][cols]; m2=new int[rows][cols]; m3=new int[rows][cols]; System.out.println("\nEnter Elements of Matrix- m1: \n"); for(int r=0;rAns. to Q3
Program ->
import java.util.*; class SearchValMatrix { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("\nEnter Number of rows of a Matrix: "); int rows=sc.nextInt(); System.out.print("\nEnter Number of columns of a Matrix: "); int cols=sc.nextInt(); int m1[][]=new int[rows][cols]; System.out.println("\nEnter Elements of Matrix- m1: \n"); for(int r=0;rAns. to Q4
Program ->
import java.util.*; class MultiplyMatrices { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("\nEnter Number of rows of a Matrix: "); int rows=sc.nextInt(); System.out.print("\nEnter Number of columns of a Matrix: "); int cols=sc.nextInt(); int m1[][],m2[][],m3[][]; m1=new int[rows][cols]; m2=new int[rows][cols]; m3=new int[rows][cols]; System.out.println("\nEnter Elements of Matrix- m1: \n"); for(int r=0;rAns. to Q5
Program ->
import java.util.*; class TransposeMatrix { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.print("\nEnter Number of rows of a Matrix: "); int rows=sc.nextInt(); System.out.print("\nEnter Number of columns of a Matrix: "); int cols=sc.nextInt(); int m1[][],m2[][]; m1=new int[rows][cols]; m2=new int[rows][cols]; System.out.println("\nEnter Elements of Matrix- m1: \n"); for(int r=0;r
Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS = 10; const int MAX_COLS = 10; class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand);...
For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...
For the program described below, document your code well. Use descriptive identifier names. Use spaces and indentation to improve readability. Include a beginning comment block as well as explanatory comments throughout. In the beginning comment block, add your name, program name, date written, program description. The description briefly describes what the program does. Include a comment at the beginning of each method to describe what the method does. Write a program to perform operations on square matrices (i.e. equal number...
Write a C program for the following: (i) (ii) (iii) (iv) (v) A function to read an NxM matrix (from console input). A function to display the NxM matrix on the screen. A function to add these two matrices. A function to subtract these two matrices. A function to multiply these two matrices. The program must also contain a main function that will first declare two 3x3 matrices A and B, allow input of data for A and B (using...
Write a java program that will read the values for 3 matrices A, B, and C and store the result of their summation in matrix D. You need to use a method to read matrix values. Use another method to add the three 3x3 matrices (each is a 2 dimensional array with 3 rows and 3 columns). Finally, use a third method to print the value of the summation (matrix D). Write a test program that will cal the three...
JAVA PROGRAM. I need to write a program in java that will perform matrix addition and both matrices have N rows and M columns, N>1 and M>1. The two matrices must be divided to four equal size sub-matrices and each sub-matrix has dimensions N/2 X M/2. I need to create four threads and each thread performs a sub-set of addition on one pair of the sub-matrices. I also need an extra thread for networking. The network part of this uses...
Bonus 1 • Write a java program to transpose a matrix mat[N][M], where: 1) You ask the user to input N and M 2) You then ask the user to input the matrix row by row 3) You transpose the matrix 4) You output the transpose to the user
Write a C++ program to read two matrices with any size. Your program should have at least the following functions: Main() Read a matrix Add two matrices Subtract two matrices Multiply two matrices Divide two matrices Display a matrix
Write a Java program that will - read two 2x3 matrices A and B. - compute their sum (C=A+B) - print out the C matrix Please write out code. No screen shots please.