编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些记录。
时间: 2024-06-14 08:03:31 浏览: 15
以下是一个实现上述功能的Python代码:
```python
def print_student_records(records):
for record in records:
print("num:", record[0])
print("name:", record[1])
print("score:", record[2])
# 主函数
if __name__ == '__main__':
# 输入5个学生的数据记录
records = []
for i in range(5):
num = input("请输入第{}个学生的学号:".format(i+1))
name = input("请输入第{}个学生的姓名:".format(i+1))
score = []
for j in range(3):
s = input("请输入第{}个学生的第{}门课的成绩:".format(i+1, j+1))
score.append(s)
records.append([num, name, score])
# 调用print函数输出这些记录
print_student_records(records)
```
相关问题
C语言编写一个函数 print,打印一个学生的成绩数组,该数组中有 5个学生的数据记录, 每个记录包括num,name,score[3],用主函数输入这些记录,用print 函数输出这些记录
以下是C语言编写的函数print,可以打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score。主函数可以输入这些记录,用print函数输出这些记录。
```c
#include <stdio.h>
struct student {
int num;
char name[20];
int score[3];
}stu[5];
void print(struct student stu[]) {
int i, j;
printf("num\tname\tscore1\tscore2\tscore3\n");
for (i = 0; i < 5; i++) {
printf("%d\t%s", stu[i].num, stu[i].name);
for (j = 0; j < 3; j++) {
printf("\t%d", stu[i].score[j]);
}
printf("\n");
}
}
int main() {
int i, j;
for (i = 0; i < 5; i++) {
printf("请输入第%d个学生的信息:\n", i + 1);
printf("num: ");
scanf("%d", &stu[i].num);
printf("name: ");
scanf("%s", stu[i].name);
for (j = 0; j < 3; j++) {
printf("score%d: ", j + 1);
scanf("%d", &stu[i].score[j]);
}
}
print(stu);
return 0;
}
```
C语言编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score[3],用主函数输入这些记录,用来输入5个学生的数据记录
以下是C语言编写的函数print,用于打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num,name,score。同时提供了一个示例主函数,用于输入这些记录,实现输入5个学生的数据记录。
```c
#include <stdio.h>
struct student {
int num;
char name[20];
int score[3];
};
void print(struct student stu[]) {
int i, j;
for (i = 0; i < 5; i++) {
printf("num:%d, name:%s, score:", stu[i].num, stu[i].name);
for (j = 0; j < 3; j++) {
printf("%d ", stu[i].score[j]);
}
printf("\n");
}
}
int main() {
struct student stu[5];
int i, j;
for (i = 0; i < 5; i++) {
printf("请输入第%d个学生的信息:\n", i + 1);
printf("num:");
scanf("%d", &stu[i].num);
printf("name:");
scanf("%s", stu[i].name);
printf("score:");
for (j = 0; j < 3; j++) {
scanf("%d", &stu[i].score[j]);
}
}
print(stu);
return 0;
}
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)