学生人数由输入确定,动态分配内存,保存学生成绩, 然后求出学生平均成绩
作者:互联网
#include <stdio.h> #include <stdlib.h> int main() { int n, i, sum = 0; scanf("%d", &n); int *p = malloc(n * sizeof(int)); if(p != NULL) { for(i = 0; i < n; i++) { scanf("%d", &p[i]); sum += p[i]; } printf("avg is %d\n", sum / n); free(p); } }
标签:成绩,int,sum,学生,分配内存,include,scanf 来源: https://www.cnblogs.com/wmt657/p/15834236.html