1.4 在 Dev C++上运行; // 在 TinyC 上,总提示'scanf' is 未定义,暂未找到解决办法
#include <stdio.h>
#include <stdlib.h>
#define N 5 //学生人数,使用宏定义可调整任意人数
#define S 80.0 //标定成绩,使用宏定义可调整任意分数
//定义学生结构体,包含学号和成绩。
typedef struct{
int num;
float score;
}Student;
//学号和成绩输入
void inputStu(Student *stu, int n){
for(int i = 0; i < n; i++){
printf("Please enter No.%d student number: ", i+1);
scanf("%d", &stu[i].num);
printf("Please enter No.%d student score: ", i+1);
scanf("%f", &stu[i].score);
}
}
//大于标定成绩的学生学号和成绩输出
void outputStu(Student *stu, int n, float score){
printf("The result of the score greater than %.1f are as follows: \n", score);
for(int i = 0; i < n; i++){
if(stu[i].score > score){
printf("No.%d student number: %d score: %.1f\n", i+1, stu[i].num, stu[i].score);
}
}
}
int main(){
Student *stu = (Student*)malloc(N * sizeof(Student));
inputStu(stu, N);
outputStu(stu, N, S);
free(stu);
system("pause");
return 0;
}