-
peng111说:
用C语言编写一个函数fun用来统计并输出某一门课的不及格人数,平均成绩和最低
成绩
#include #define N 20 void fun(float a[N], int n) { int i, j=0; float temp, avg, min=a[0]; for (i=0; i a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } for (i=1; i<n; i++) avg += a[i]; avg /= n-1; printf("不及格人数: %d\n平均成绩: %.2f\n最低成绩: %.2f\n", j, avg, min); } int main() { float a[N] = {78.5, 98.0, 57.3, 60.8, 70.2, 59.6, 80.1, 65.8, 82.7, 89.9, 55.0, 74.8, 83.3, 74.4, 71.0, 91.1, 81.2, 63.4, 99.9, 67.8}; int n = N; fun(a, n); return 0; }
-
@ChatGPT #include
#define N 20void fun(float a[N], int n)
{
int i, j=0;
float temp, avg, min=a[0];
for (i=0; i a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
for (i=1; i<n; i++)
avg += a[i];
avg /= n-1;
printf("不及格人数: %d\n平均成绩: %.2f\n最低成绩: %.2f\n", j, avg, min);
}int main()
{
float a[N] = {78.5, 98.0, 57.3, 60.8, 70.2, 59.6, 80.1, 65.8, 82.7, 89.9, 55.0, 74.8, 83.3, 74.4, 71.0, 91.1, 81.2, 63.4, 99.9, 67.8};
int n = N;
fun(a, n);
return 0;
}解释一下