Advertisements
Advertisements
प्रश्न
Write a program for the following.
Fill a double dimensional array of order 5 × 4. Print its transpose.
[The transpose of a matrix is found by interchanging the Rows and Columns]
कोड लेखन
Advertisements
उत्तर
importjava.util.*;
class Q3
{
public void main()
{
int RC[ ][] = new int [5][4];
int r = 0, с = 0;
Scanner sc = new Scanner(System.in);
for(r = 0; r<5; r++)
{
for(c = 0; c<4; c++)
{
System.out.print(" Enter value for cell number " + r +""+c+"::");
RC[r][c] = sc.nextInt();
}
}
System.out.println(" Printing the array: ");
for(r = 0; r<5; r++)
{
for(c = 0; c< 4; c++)
{
System.out.print(" "+ RC[r] [c]);
}
System.out.println();
}
System.out.println(" Printing the transpose of the array : ");
for(c = 0; c<4; c++)
{
for(r = 0; r<5; r++){
{
System.out.print(" "+ RC[r][c]);
}
System.out.println();
}
}
}shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 9: Arrays - Double Dimension - Exercises [पृष्ठ २२१]
