# Design a function, which is used to find the average value of a two-dimensional double array of any size.

2022-01-27 02:43:37

/* Title Description
Design a function , This function is used to find a two-dimensional space of any size double Average value of type array .
The name of this function is matrixAvg
Please use the following main Function test the function you designed
int main(){
int M,N;
scanf("%d%d",&M,&N);
double aver,a[M][N];
int i,j;
for(i=0;i<M;i++)
for(j=0;j<N;j++)
scanf("%lf",&a[i][j]);
aver=matrixAvg(M,N,a);
printf("%.2f\n",aver);
return 0;
}
Input description
Enter the integer in the first line M and N
Start with the second line , Input M That's ok , Enter... On each line N individual double The number of types
Output the average value of the array /
#include<stdio.h>
float matrixAvg(int m,int n,double a[100][100])
{
int i,j;
double average;
double sum=0.0;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
scanf("％lf",&a[i][j]);
sum+=a[i][j];
}
average=sum/(m
n);
return average;
}
int main()
{
int M,N;
scanf("%d%d",&M,&N);
double aver,a[M][N];
int i,j;
for(i=0;i<M;i++)
for(j=0;j<N;j++)
scanf("%lf",&a[i][j]);
aver=matrixAvg(M,N,a);
printf("%.2f\n",aver);
return 0;
}
/ How can I change this program ？ By the way, could you tell me where I used to sit ？/

Why does it appear in the function you find the average scanf ah

Arrays open up memory when they are defined , So the array can't be resized by inputting variables if it wants to be large .
That is, arrays double a[m][n], in ,m and b It can't be a variable , It has to be a certain value .

author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270243344317.html