📄 text6.c
字号:
#include <conio.h>
#include <stdio.h>
#include <malloc.h>
#define SIZE 5
struct student{
int no;
int score1;
int score2;
int average;
};
void input(struct student *scores[SIZE]){
int i;
for(i = 0; i < SIZE; i++){
printf("please input the %dth score:\n",i+1);
printf("学号:");
scanf("%d",&scores[i]->no);
printf("第一门课的成绩:");
scanf("%d",&scores[i]->score1);
printf("第二门课的成绩:");
scanf("%d",&scores[i]->score2);
scores[i]->average = (scores[i]->score1+scores[i]->score2)/2;
if(i < SIZE -1)
printf("\ninput next....\n\n");
}
printf("\n\ninput complete.\n\n");
}
void output(struct student *scores[SIZE]){
int i;
printf("学号 第一门课的成绩 第二门课的成绩 平均成绩\n");
for(i = SIZE -1; i >= 0 ; i --){
printf("%d%11d%19d%12d",
scores[i]->no,
scores[i]->score1,
scores[i]->score2,
scores[i]->average);
printf("\n");
}
}
void main(){
struct student *scores[SIZE];
int i;
for(i = 0;i < SIZE; i++){
scores[i] = malloc(sizeof(struct student));
}
input(scores);
output(scores);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -