I am learning to pass arrays to functions. My problem is this : I will scan a 2-D array in main() function. Pass the order n of the matrix and the address of first element to a function called pass(). Then I will print all the elements in pass().
I cannot understand what is wrong with my code. Please point out my mistake.
Code:
# include<stdio.h>
main()
{
float a[50][50];
int i, j, n ;
void pass( int , float* ) ;
printf("Enter n : ") ;
scanf("%d", &n) ;
for( i = 0; i < n ; i++)
{
for( j = 0; j < n ; j++)
{
printf("\n Enter a%d%d = ", i, j) ;
scanf("%f", &a[i][j]) ;
}
}
pass(n, &a[0][0]) ;
}
void pass( int n, float *a_pointer )
{
int i, j ;
for( i = 0; i < n ; i++)
{
for( j = 0; j < n ; j++)
{
printf("\n\n %f", *(a_pointer + n*i + j )) ;
}
}
}