From 102e1f2dc1dee6215ef10a8339d3a28acc4072cb Mon Sep 17 00:00:00 2001 From: adithyaanilkumar Date: Mon, 29 Jun 2020 09:40:32 +0530 Subject: [PATCH] added array to func --- C/2d_array_to_func.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/C/2d_array_to_func.c b/C/2d_array_to_func.c index e69de29..3f3ede7 100644 --- a/C/2d_array_to_func.c +++ b/C/2d_array_to_func.c @@ -0,0 +1,31 @@ +//Passing 2D array to function + +#include + +double average(int [][2], int, int); //no need to specify array/variable names in this step + +void main() +{ + int M=3,N=2; + + double mean; + int matrix[3][2]= + { + {1,2}, + {3,4}, + {5,6} + }; + + mean = average(matrix,M,N); + printf("average over the matrix is %f", mean); +} + +double average(int x[][2],int M,int N) // require bounds for all dimensions except the first +{ + int i, j; + double sum = 0.0; + for (i=0; i