text6.c

来自「编制一个程序」· C语言 代码 · 共 50 行

C
50
字号
#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 + =
减小字号Ctrl + -
显示快捷键?