| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：10  回复次数：3

#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;
}
得分:0

得分:10

```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++)
{
count2 = 0;
if (number[j]>*pMax)
{
*pMax = number[j];
}

if (number[j]<*pMin)
{
*pMin = number[j];
}

if (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;
}```
得分:0

• 4
• 1/1页
• 1