注:我是菜鸟那位帮忙解下
谢谢了
/* Note:Your choice is C IDE */
#include "stdio.h"
main()
{
int a[10],i,t1=0,t2=0,aver1,aver2,sum1=0,sum2=0;
printf(" Please input a\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("输入的数据是:\n");
for(i=0;i<10;i++)
printf("%3d\n",a[i]);
for(i=0;i<10;i++)
{ if(a[i]%2==1)
{ t1+=1;
sum1=sum1+a[i];
}
else
{ t2+=1;
sum2=sum2+a[i];
}
}
aver1=sum1/t1;
aver2=sum2/t2;
printf("奇数的个数是 :%d\n奇数的平均值是 :%d\n",t1,aver1);
printf("偶数的个数是 :%d\n偶数的平均值是 :%d\n",t2,aver2);
}
这是我个人作法,可能不够好.
#include "stdio.h"
#include "math.h"
#define N 8
main()
{
int a[N],i,s1=0,s2=0;/*s1,s2分别为偶数和奇数个数*/
float sum1=0,sum2=0;
printf("input the array:");
for(i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<N;i++)
{
if(a[i]%2==0)
{
s1+=1;
sum1+=a[i];
}
else
{
s2+=1;
sum2+=a[i];
}
}
sum1/=s1;
sum2/=s2;
printf("the even's number:%3d;the odd's number:%3d;the even's aver:%5.2f;the odd's aver:%5.2f.\n",s1,s2,sum1,sum2);
}