Multi-dimensional array


Multi-dimensional array  

These arrays are capable of storing data in rows & columns. Each row in the array is associated with how many columns you have defined for the array, the only drawback is the fact that the entire array must contain elements of some database which is defined when you declare the array.  

 

Declaration of two-dimensional array  

<datatype><array-name[size1][size2]> 

 

QUESTION:- Addition and multiplication of an array  

#include <stdio.h>

#include <conio.h>

void main()

{

    int arr[10], arr1[10], arr2[10], arr3[10], ino;

    printf("enter a number for array: ");

    scanf("%d", &no);

    // first array input

    printf("enter an %d array: \n"no);

    for (i = 0i < noi++)

    {

        scanf("%d", &arr[i]);
    }

    // second array input

    printf("enter an second %d array: \n"no);

    for (i = 0i < noi++)

    {

        scanf("%d", &arr1[i]);
    }

    // adding the array

    for (i = 0i < noi++)

    {

        arr2[i] = arr[i] + arr1[i];
    }

    // multiplication of an array

    for (i = 0i < noi++)

    {

        arr3[i] = arr[i] * arr1[i];
    }

    // sum of an array with multiplication

    printf("Sum the array\n");

    for (i = 0i < noi++)

    {

        printf("Sum of [%d] location array is %d \n"iarr2[i]);

        printf("the multiplication of %d with %d array is %d \n"arr[i], arr1[i], arr3[i]);

        printf("\n");
    }

    getch();
}


OUTPUT

enter a number for array: 5

enter a 5 array: 

1 4 7 8 9 6

enter a second 5 array: 

2 3 6 9 8 5 

Sum the array

The Sum of [0] location array is 7

the multiplication of 1 with 6 arrays is 6


The Sum of [1] location array is 6

the multiplication of 4 with 2 arrays is 8


The Sum of [2] location array is 10

the multiplication of 7 with 3 arrays is 21


The Sum of [3] location array is 14

the multiplication of 8 with 6 arrays is 48


The Sum of [4] location array is 18

the multiplication of 9 with 9 arrays is 81


Follow our page for regular updates.

0 Comments