数组a有n个数,编一函求素数的个数a,满足条件数的平均值b,及不满足的四位数平均值c调用函数把结果abc输出

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:20:13

//本程序的功能:数组array有N个数,编一函数,求素数的个数a,满足条件数的平均值b,及不满足的四位数平均值c调用函数把结果abc输出

#include <stdio.h>
#include <math.h>

#define N 10

void GetIn(int *aPointer);
int IsPrime(int num); //函数声明语句
void nPrint(int a,long b,long c);

int main(void)
{
static int array[N];
int i=0;
int flag;
int nCount=0;
long SumPrime=0;
long SumOther=0;

GetIn(array); //录入数组内容

//逐个判断是否是素数
for(i=0;i<N;i++)
{
flag=IsPrime(array[i]);

if (flag==1)
{
nCount++;
SumPrime+=array[i];
}
else
{
SumOther+=array[i];
}
}

nPrint(nCount,SumPrime,SumOther); //输出相关的数据信息

return 0;
}

/*函数功能:录入数组内容
传入参数:数组的地址指针
返回值:无*/
void GetIn(int *aPointer)
{
int j=0;

for (j=0;j<N;j++)
{
printf("Please enter the %dth numb