c语言,我看我这段代码显示出来好多错误,我看起来都没错,而且它显示的错误都看不懂,都哪里有错?
#include<stdio.h>#include<stdlib.h>#defineN10intmain(){inti;structstudent{intnum;char...
#include<stdio.h>#include<stdlib.h>#define N 10int main(){ int i; struct student{ int num; char name[8]; char sex; int age; double grade;}; struct student stu[N]; struct student stumax,stumin; FILE *fp; fp=fopen("aa.txt","r"); if (fp==NULL) {printf("文本打开出错!"); exit(0); } for(i=0;i<N;i++) fscanf(fp,"%d %s %s %d %1f",&stu[i].num,&stu[i].name,&stu[i].sex,&stu[i].age,&stu[i].grade); stumax.grade=0;stumin.grade=100; for(i=0;i<N;i++) { if (stu[i].grade<=stumin.grade) stu[i]=stumin.grade; if (stu[i].grade>=stumax.grade) stu[i]=stumax.grade; } printf("最大值和最小值分别是\n",stumax,stumin); }
展开
3个回答
展开全部
修改过了:
#include<stdio.h>
#include<stdlib.h>
#define N 10
int main()
{ int i;
struct student
{ int num;
char name[8];
char sex;
int age;
double grade;
};
struct student stu[N];
struct student stumax,stumin;
FILE *fp;
fp=fopen("aa.txt","r");
if (fp==NULL)
{ printf("文本打开出错!");
exit(0);
}
for(i=0; i<N; i++)
fscanf(fp,"%d %s %s %d %lf",&stu[i].num,&stu[i].name,&stu[i].sex,&stu[i].age,&stu[i].grade);
stumax.grade=0;
stumin.grade=100;
for(i=0; i<N; i++)
{ if (stu[i].grade<stumin.grade) stumin.grade=stu[i].grade;
if (stu[i].grade>stumax.grade) stumax.grade=stu[i].grade;
}
printf("最大值和最小值分别是%f\t%f\n",stumax.grade,stumin.grade);
}
#include<stdio.h>
#include<stdlib.h>
#define N 10
int main()
{ int i;
struct student
{ int num;
char name[8];
char sex;
int age;
double grade;
};
struct student stu[N];
struct student stumax,stumin;
FILE *fp;
fp=fopen("aa.txt","r");
if (fp==NULL)
{ printf("文本打开出错!");
exit(0);
}
for(i=0; i<N; i++)
fscanf(fp,"%d %s %s %d %lf",&stu[i].num,&stu[i].name,&stu[i].sex,&stu[i].age,&stu[i].grade);
stumax.grade=0;
stumin.grade=100;
for(i=0; i<N; i++)
{ if (stu[i].grade<stumin.grade) stumin.grade=stu[i].grade;
if (stu[i].grade>stumax.grade) stumax.grade=stu[i].grade;
}
printf("最大值和最小值分别是%f\t%f\n",stumax.grade,stumin.grade);
}
追问
你给的代码是正确的,但是我把我的代码修改之后,居然出错了,运行结果不正确,两个都是0.00...而且我看了半天,代码跟你的一模一样,这是怎么回事?
展开全部
#include<stdio.h>
#include<stdlib.h>
#define N 10
int main(){
int i;
struct student{
int num;
char name[8];
char sex;
int age;
double grade;
};
struct student stu[N];
struct student stumax,stumin;
FILE *fp;
fp=fopen("aa.txt","r");
if (fp==NULL){
printf("文本打开出错!");
exit(0);
}
for(i=0;i<N;i++)
fscanf(fp,"%d %s %c %d %lf",&stu[i].num,stu[i].name,&stu[i].sex,&stu[i].age,&stu[i].grade);
stumax.grade=0;
stumin.grade=100;
for(i=0;i<10;i++){
if (stu[i].grade<=stumin.grade)
stumin.grade=stu[i].grade;
if (stu[i].grade>=stumax.grade)
stumax.grade=stu[i].grade;
}
printf("最大值和最小值分别是%lf,%lf\n",stumax.grade,stumin.grade);
}
#include<stdlib.h>
#define N 10
int main(){
int i;
struct student{
int num;
char name[8];
char sex;
int age;
double grade;
};
struct student stu[N];
struct student stumax,stumin;
FILE *fp;
fp=fopen("aa.txt","r");
if (fp==NULL){
printf("文本打开出错!");
exit(0);
}
for(i=0;i<N;i++)
fscanf(fp,"%d %s %c %d %lf",&stu[i].num,stu[i].name,&stu[i].sex,&stu[i].age,&stu[i].grade);
stumax.grade=0;
stumin.grade=100;
for(i=0;i<10;i++){
if (stu[i].grade<=stumin.grade)
stumin.grade=stu[i].grade;
if (stu[i].grade>=stumax.grade)
stumax.grade=stu[i].grade;
}
printf("最大值和最小值分别是%lf,%lf\n",stumax.grade,stumin.grade);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
3 成书过程w4 人物形象? 主要人物
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询