20_10

Write a C program to pass multidimensional array to a function as it's parameter.

 Source code:

/*Consider a program, of passing multidimensional array to a function. Consider an two dimensional array of size 3x3 and write a function. Write a function displayarray() by passing two dimensional array as it's parameter.*/


#include<stdio.h>

void displayarray(int arr[3][3]);

void displayarray(int arr[3][3])

{

    int i, j;

    printf("The complete array is");

    for (i = 0; i < 3; ++i)

    {

        printf("\n");

                 

      for (j = 0; j < 3; ++j)

        {

            printf("%d ", arr[i][j]);

        }

    }

}

int main()

{

    int arr[3][3], i, j;

    /* Read 9 elements */    

    printf("Enter a matrix:\n");

for (i = 0; i < 3; ++i)

    {

        for (j = 0; j < 3; ++j)

        {

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

        }

    }

   /* passing the array as argument */

    displayarray(arr);

    return 0;

}

Output:
C program to pass multidimensional array to a function as it's parameter


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...