-
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;
}解释一下
-
peng111说:
#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 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;
}解释一下
:
这段代码的功能是对N个成绩进行排序,计算不及格人数、平均成绩和最低成绩。
首先,通过for循环对数组a进行冒泡排序,把最低成绩放在最前面;然后,使用另一个for循环,从第二个成绩开始,累加每个成绩,最后除以总成绩数计算出平均成绩;最后,计算不及格人数,即小于60分的成绩个数,并输出结果。 -
Eqwer说:
用C++编写base64的加密代码
#include #include static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) { std::string ret; int i = 0; int j = 0; unsigned char char_array_3[3]; unsigned char char_array_4[4]; while (in_len--) { char_array_3[i++] = *(bytes_to_encode++); if (i == 3) { char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; char_array_4[1] = ((char_array_3[0] & 0x03) > 4); char_array_4[2] = ((char_array_3[1] & 0x0f) > 6); char_array_4[3] = char_array_3[2] & 0x3f; for(i = 0; (i > 2; char_array_4[1] = ((char_array_3[0] & 0x03) > 4); char_array_4[2] = ((char_array_3[1] & 0x0f) > 6); char_array_4[3] = char_array_3[2] & 0x3f; for (j = 0; (j (s.c_str()), s.length()); std::cout << encoded << std::endl; return 0; }
-
peng111说:
用C语言编写一个函数fun用来统计并输出语文课的不及格人数,定义一个数组,来保存学生成绩,求平均成绩和最低并展示
不及格人数
#include #define STUDENT_NUM 10 void fun(int score[], int size) { int avg = 0; int min = score[0]; int fail_num = 0; for (int i = 0; i < size; i++) { avg += score[i]; if (score[i] < min) min = score[i]; if (score[i] < 60) fail_num++; } avg /= size; printf("平均成绩:%d\n", avg); printf("最低成绩:%d\n", min); printf("不及格人数:%d\n", fail_num); } int main(void) { int score[STUDENT_NUM] = {90, 65, 75, 88, 88, 82, 76, 88, 94, 79}; fun(score, STUDENT_NUM); return 0; }