हिंदी

Write a program to store numbers in two double dimensional arrays a and b. Find a b and store in another array c. Print the array c.

Advertisements
Advertisements

प्रश्न

Write a program to store numbers in two double dimensional arrays a and b. Find a b and store in another array c. Print the array c.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
public class DDA4
{
    public void main()
    {
        Scanner sc = new Scanner(System.in);
        int AR1[ ][ ] = new int[4][5];
        int AR2[ ][ ] = new int[4][5];
        int AR3[ ][ ] = new int[4][5];
        int r, c;
        System.out.println("Filling array1: ");
        for (r = 0; r < 4; r++)
        {
            for (c = 0; c < 5; c++)
            {
                //System.out.print("Cell[" + r+"]["+ c +"] : " );
                AR1[r][c] = (int)(Math.random() * 100);
            }
        }
        System.out.println("Filling array2: ");
        for (r = 0; r < 4; r++)
        {
            for (c = 0; c < 5; c++)
            {
                //System.out.print("Cell[" + r+"][“+ c +"] : “ );
                AR2[r][c] = (int)(Math.random() * 100);
            }
        }
        System.out.println("Filling array3: ");
        for (r = 0; r < 4; r++)
        {
            for (c = 0; c < 5; c++)
            {
                //System.out.print("Cell[" + r+"]["+ c +"] : " );
                AR3[r][c] = AR1[r][c] * AR2[r][c];
            }
        }
        System.out.println("The array1 is : ");
        for (r = 0; r < 4; r++)
        {
            for (c = 0; c < 5; c++)
            {
                System.out.print(AR1[r][c] + "\t");
            }
            System.out.println();
        }
        System.out.println("The array2 is : ");
        for (r = 0; r < 4; r++)
        {
            for (c = 0; c < 5; c++)
            {
                System.out.print(AR2[r][c] + "\t");
            }
            System.out.println();
        }
        System.out.println("The product array is: ");
        for (r = 0; r < 4; r++)
        {
            for (c = 0; c < 5; c++)
            {
                System.out.print(AR3[r][c] + "\t");
            }
            System.out.println();
        }
    }
}

Output:

Filling array1:
Filling array2:
Filling array3: 
The array1 is :
60 34 8 11 36 7 82
7 86 87
12 22 91 87 99
63 67 31 27 13
The array2 is:
6 16 63 85 80
27 36 22 77 11
39 45 53 51 42
25 11 0 2 56
The product array is :
360 544 504 935 2880
189 2952 154 6622 957
468 990 4823 4437 4158
1575 737 0 54 728

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 11: Programs Overall - Double Dimensional Arrays [पृष्ठ २५२]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 11 Programs Overall
Double Dimensional Arrays | Q 4. | पृष्ठ २५२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×