c语言入门小问题 继续解答
# include<stdio.h>double average ( int n)
{int iCounter = 0,iGrade;
float fAverage =0;
do
{
++iCounter;
printf("输入课程成绩:");
scanf("%d",&iGrade);
fAverage+=iGrade;
}while(iCounter<n);
fAverage/=n;
return fAverage;
}
float max(float f1,float f2, float f3)
{
float fMax=f1;
if(f2>fMax)
fMax=f2;
if(f3>fMax)
fMax=f3;
return fMax;
}
float count()
{
int iGrade,iYes,iNum;
float fCount;
do
{
++iNum;
printf("输入C语言成绩:");
scanf("%d",&iGrade);
if(iGrade>=60)
{++iYes;}
}while(iGrade!=-1);
fCount=(float)iYes/iNum;
printf("班级及格率为:%f",fCount);
}
int main()
{
float fAverage,fAverage1,fAverage2,fAverage3;
fAverage=average(3);
printf("平均成绩为:%.2f\n",fAverage);
printf("输入三个学生的成绩:\n");
scanf("%f%f%f",&fAverage1,&fAverage2,&fAverage3);
printf("平均分最高的是:%.2f\n",max(fAverage1,fAverage2,fAverage3));
count();
return 0;
}