求输入的十个整数中正数的个数及其平均值。
程序员文章站
2024-02-03 17:06:58
...
#include <stdio.h>
#define SIZE 10
void main()
{
int x[SIZE],i,n=0;
float sum=0;
printf("Enter 10 integers:\n");
for(i=0;i<SIZE;i++)
{
printf("%d:",i+1);
scanf("%d",&x[i]);
if(x[i]>0)
{
sum+=x[i];
n++;
}
}
printf("the counter is %d\n",n);
printf("the average is %f\n",sum/n);
}