用C#编程从键盘输入n个人的成绩,统计出平均成绩,并输入高于平均分的人数和成绩

2024-12-25 14:04:35
推荐回答(3个)
回答1:

int n=10,aver=0,a=0;
int[]A=new int[n];
console.writeline("输入成绩");
for(i=0;i {
A[i]=console.readline();
}
aver=Average(A,n);
for(i=0;i {
if(A[i]>aver)
a++;
}
console.writeline("平均分:{0}",aver);
console.writeline("高于平均分人数:{0}",a);

int Average(int[]A,int n)
{
int i,sum=0;
for(i=0;i {
sum+=A[i];
}
return sum/n;
}
注:代码没测试过,但也八九不离十了,可作参考

回答2:

#include
#include
#define N 100
int Average(int A[],int n);
int main()
{
int A[N],aver,n,i,a=0,b=0;
printf("Input n:\n");
scanf("%d",&n);
printf("Input score:\n");
for(i=0;i {
scanf("%d",&A[i]);
}
aver=Average(A,n);
printf("Average score is %d\n",aver);
for(i=0;i {
if(A[i]>aver)
a++;
else if(A[i] b++;
}
printf("The higher people is %d\n",a);
printf("The lower people is %d\n",b);
return 0;
}
int Average(int A[],int n)
{
int i,sum=0;
for(i=0;i {
sum+=A[i];
}
return sum/n;
}

回答3:

都有内置函数啦