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;
}
No comments:
Post a Comment