मराठी

Write a program for the following. Fill a double dimensional array of order 4 × 4. Print the left and right diagonal elements of the array.

Advertisements
Advertisements

प्रश्न

Write a program for the following.

Fill a double dimensional array of order 4 × 4. Print the left and right diagonal elements of the array.

कोड लेखन
Advertisements

उत्तर

importjava.util.*;
class Q2
{
    public void main()
    {
       int RC[ ][] = new int [4][4];
       int r = 0, с = 0;
       Scanner sc = new Scanner(System.in);
       for(r = 0; r<4; 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("\n Printing the left diagonal of the array :");
    for(r = 0; r<4; r++)
    {
            System.out.print(" " + RC[r][r]);
    }
    System.out.println("\n Printing the right diagonal of the array: ");
    for(r = 0; r<4; r++)
    {
          System.out.print(" " + RC[r][3-r]);
    }
  }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 9: Arrays - Double Dimension - Exercises [पृष्ठ २२१]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 9 Arrays - Double Dimension
Exercises | Q 1. (ii) | पृष्ठ २२१
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×