/**********************
*有10个学生,每个学生考3门课,要求编一函数,能检查学生有无不及格的课程,
*如果有某一学生有一门或一门以上课程不及格,就输出该学生的学号和其全部成绩
**********************/
#include <stdio.h>
#define X 2 //学生数目(这里改成10就可以拉)
struct student
{
int num; //编号
int first; //第一门
int second; //第二门
int third; //第三门
};
struct student stu[X];
void main()
{
int i;
int flag=1;
printf("请输入10个学生的编号与成绩(格式:编号 成绩 成绩 成绩):\n");
for(i=1;i<=X;i++)
scanf("%d %d %d %d",&stu[i].num,&stu[i].first,&stu[i].second,&stu[i].third);
printf("结果:\n");
for(i=1;i<=X;i++)
if(stu[i].first<60 || stu[i].second<60 || stu[i].third<60)
{printf("%d %d %d %d\n",stu[i].num,stu[i].first,stu[i].second,stu[i].third);
flag=0;}
if(flag)
printf("没有不合格的!\n");
}
实现都在里面拉,函数就不另外写拉.不知道写的对不对,我测试是没问题.刚刚学C,不足处请提出.
下面是结果:
请输入10个学生的编号与成绩(格式:编号 成绩 成绩 成绩):
1 70 80 90
2 80 90 100
结果:
没有不合格的!