#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define STUDENT_COUNT 50
#define GRADE_THRESHOLD 80
int main(){
srand(time(NULL));
for(int student_id=1;student_id<=STUDENT_COUNT;student_id++){
int grade=rand()%101;
if(grade>GRADE_THRESHOLD){
printf("学生的学号: %d,成绩为:%d\n",student_id,grade);
}
}
return 0;
}
or
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define STUDENT_COUNT 50
#define GRADE_THRESHOLD 80
// 函数原型声明
int generateGrade();
void checkAndPrintGrade(int student_id, int grade);
int main() {
srand(time(NULL)); // 随机数生成器初始化
for (int student_id = 1; student_id <= STUDENT_COUNT; student_id++) {
int grade = generateGrade(); // 生成成绩
checkAndPrintGrade(student_id, grade); // 检查并打印成绩
}
return 0;
}
// 生成并返回一个0到100之间的随机成绩
int generateGrade() {
return rand() % 101;
}
// 检查成绩是否超过阈值,如果是,则打印学生ID和成绩
void checkAndPrintGrade(int student_id, int grade) {
if (grade > GRADE_THRESHOLD) {
printf("Student ID %d has a grade of %d\n", student_id, grade);
}
}