题解 | #班级成绩输入输出#
班级成绩输入输出
https://www.nowcoder.com/practice/60d96b08e1cb42e38629d54e37eac008
指针版本
#define STUDENTS 5 #define GRADES 6 int main() { double data[STUDENTS][GRADES] = {0.0}; //初始化不赋值的话,仅仅是创建了一片内存,没有分配内存地址 double* ptd,*ptsum; int stu; for (stu = 0; stu < STUDENTS; stu++) { ptd = data[stu]; //指针指代学生信息 ptsum = &data[stu][GRADES-1]; while (ptd < ptsum) { scanf("%lf", ptd); *ptsum += *ptd; ptd++; } } for (stu = 0; stu < STUDENTS; stu++) { ptd = data[stu]; //指针指代学生信息 ptsum = &data[stu][GRADES - 1]; while (ptd < ptsum) { printf("%.1f ", *ptd); ptd++; } printf("%.1f\n", *ptd); } return 0; }