简单的一个用指针求最大值最小值 素数平均数 奇数平均数 出现问题了 求指教
#include<stdio.h>#include<stdlib.h>
#include<time.h>
void Find(int number[], double *pMax, double *pMin, double *pAver1, double *pAver2);
main()
{
int i, k;
double Max, Min, aver1, aver2;
int number[300]={0};
srand(time(NULL));
for( i=0; i<300; i++ )
{
k = rand()%926+71;
number[i] = k;
}
Find( number, &Max, &Min, &aver1, &aver2 );
printf("最大值是:%f\n,最小值是:%f\n,奇数的平均数是:%f\n,质数的平均数是:%f\n",Max, Min, aver1, aver2);
return 0;
}
void Find( int number[], double *pMax, double *pMin, double *pAver1, double *pAver2 )
{
int j, m, sum1, sum2, count1, count2, count3;
m = 0;
sum1 = 0;
sum2 = 0;
count1 = 0;
count2 = 0;
count3 = 0;
*pMax = number[0];
*pMin = number[0];
*pAver1 = 0;
*pAver2 = 0;
for( j=0; j<300; j++ )
{
if( number[j]>*pMax )
{
*pMax = number[j];
}
if( number[j]<*pMin )
{
*pMin = number[j];
}
while( number[j]%2!=0 )
{
sum1 += number[j];
count1++;
}
for( m=2; m<number[j]; m++ )
{
if( number[j]%m==0 )
{
count2++;
}
}
if( count2 ==0 )
{
sum2 += number[j];
count3++;
}
}
*pAver1 = sum1/count1;
*pAver2 = sum2/count3;
}