VISIT GITHUB TO SEE MY PROJECTS GO

TRANSPOSE MATRIX | ISC COMPUTER 2024 | survnor.blogspot.com

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

 


Write a program in java to accept and store the number in a 4x4 matrix in a DDA. Find the transpose in a matrix by using an assignment statement. The transpose of a matrix is obtain when we change row elements and column and vice versa.

 

ALGORITHM

 

STEP 1:- Start.

STEP 2:- Declare  transpose as a class.declare and initialize variables i,j arr[][],trp[][].

STEP 3:- Declare trans as a method with return type void ..now enter the elements of  4*4 square matrix using nested loop...inner loop on j strating with 0 and upto less than 4 incremented by 1 and outer loop on i strating with 0 and upto less than 4 incremented by 1 in each step....along with the message " ENTER THE NUMBER OF MATRIX 4*4".

STEP 4:- Now display the array elements in the form of square matrix along with the message "the user given matrix- ".

STEP 5:- Now within the nested loop (inner loop on j strating with 0 and upto less than 4 incremented by 1 and outer loop on i strating with 0 and upto less than 4 incremented by 1 in each step) store the value of square matrix a[i][j] in trp[j][i].

STEP 6:- Now again start a nested loop print the transpose of the user given matrix along with the message "transpose of the given matrix".

STEP 7:- Now close the method trans().

STEP 8:- Now declare main() function.. create object ob of the class transpose and call the method trans()  through the object ob.

STEP 9:- Now close the main function and the class transpose.

STEP 10:- Stop.

 

 

 

 

 

 

 

 

 

 

 

 

 

SOURCE CODE

 

import java.util.*;

class transpose{

    int i,j;

    Scanner sc=new Scanner(System.in);

    int arr[][]=new int[4][4];

    int trp[][]=new int[4][4];

    void trans(){

        System.out.println("ENTER THE NUMBER OF MATRIX 4*4:");

        for(i=0;i<4;i++){

            for(j=0;j<4;j++){

                arr[i][j]=sc.nextInt();}}

        System.out.println("THE NUMBER OF MATRIX ARE:");

        for(i=0;i<4;i++){

            for(j=0;j<4;j++){

                System.out.print(arr[i][j]+" ");}

            System.out.println();}

        for(i=0;i<4;i++){

            for(j=0;j<4;j++){

                trp[j][i]=arr[i][j];}}

        System.out.println("TRANSPOSE OF THE MATRIX IS:");

        for(i=0;i<4;i++){

            for(j=0;j<4;j++){

                System.out.print(trp[i][j]+" ");}

            System.out.println();}}

    public static void main(){

        transpose ob=new transpose();

        ob.trans();}}

 

 

 

 

 

 

VARIABLE DESCRIPTION

 

S.L.No.

Name

Data Type

Description

1

i,j

int

These are loop control variables.

2

arr[][]

int

Declare as a double dimensional array to sotre array elements.

3

trp[][]

int

Declare as a  double dimensional array to store the transpose of the matrix.

 

INPUT AND OUTPUT

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.