一个关于二位数组作为函数参数的问题 求解
程序如下 #include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define N 99
int main(void)
{
int i,j,n,a[N],sum1=0,sum2=0,b[N][N],x,y;
float p[N],X[N][N],HX,HXY;
float ComputingHx(float b[],int n);
float ComputingHxy(float *p,int n);
srand( (unsigned)time(0) );//产生随机P(X)
n = rand()%10;
while(n==0||n==1) //防止产生0个或者1个概率
{
srand( (unsigned)time(0) );
n = rand()%10;
} //防止产生0个或者1个概率
for(i=0;i<n;i++)
{
a[i] = rand()%100;
sum1+=a[i];
}
printf("P(X)\t");
for(i=0;i<n;i++)
{
p[i] = ((float)a[i])/((float)sum1);
}
for(i=0;i<n;i++)
{
printf("%.3f\t",p[i]);
}
printf(" \n ");//产生随机P(X)
srand( (unsigned)time(0) );//产生随机P(XY)
x = rand()%10;
y = rand()%10;
while((x==0||x==1)||(y==0||y==1)) //防止产生0个或者1个概率
{
srand( (unsigned)time(0) );
x = rand()%10;
y = rand()%10;
} //防止产生0个或者1个概率
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
b[i][j] = rand()%100;
sum2+=b[i][j];
}
}
printf("\n\nP(XY)\t");
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
X[i][j] = ((float)b[i][j])/((float)sum2);
}
}
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
printf("%.3f\t",X[i][j]);
}
printf("\n\t");
}
printf(" \n ");//产生随机P(XY)
HX = ComputingHx(p,n);
printf("H(X) = %f\n",HX);
HXY = ComputingHxy(X,x*y);
printf("H(XY) = %f\n",HXY);
}
float ComputingHx(float b[],int n)
{
int i;
float Hx;
for(i=0;i<n;i++)
Hx = b[i]*log(1/b[i]);
return Hx;
}
float ComputingHxy(float *p,int n)
{
float *end;
float Hxy = 0;
end = p+n;
for(;p<end;p++)
{
Hxy +=(*p)*log(1/(*p));
}
return Hxy;
}
不懂那个参数是怎么传的 求大神求教 !!