编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
 
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
 14 12
发新话题
打印

哎,大一的题目都不会做了

哎,大一的题目都不会做了

#define M 5 /*设一共有5个学生*/ #define N 6 /*设一个学生有六门课*/ typedef struct { float score[N]; int num; /*学生学号*/ }student; main() { int i,j,k; float total,sum; student a[M]; for(i=0;i<M;i++) { printf("please input the number of %d student:\n",i); scanf("%d",&a[i].num); printf("please input the i student score:\n",i); for(j=0;j<N;j++) scanf("%f",&a[i].score[j]); printf("\n"); }

for(i=0;i<M;i++) for(j=0;j<N;j++) if(a[i].score[j]<60) {printf("the student's number is:%d\n",a[i].num); printf("his score is:"); for(k=0;k<n;k++) {printf("%d",a[i].score[k]); sum+=a[i].score[k];} printf("the average is:\n",sum/N); } }

这个有错误,谁能帮我改一下下呀,thank you 先

TOP

#include <stdio.h> #define M 5 /*设一共有5个学生*/ #define N 6 /*设一个学生有六门课*/ typedef struct { float score[N]; int num; /*学生学号*/ }student; void main() { int i,j,k; float total,sum; student a[M]; for(i=0;i<M;i++) { printf("please input the number of %d student:\n",i); scanf("%d",&a[i].num); printf("please input the i student score:\n",i); for(j=0;j<N;j++) scanf("%f",&a[i].score[j]); printf("\n"); }

for(i=0;i<M;i++) for(j=0;j<N;j++) if(a[i].score[j]<60) {printf("the student's number is:%d\n",a[i].num); printf("his score is:"); for(k=0;k<N;k++) {printf("%d",a[i].score[k]); sum+=a[i].score[k];} printf("the average is:\n",sum/N); } }

我渴望掌控时空的核心——用最先进的技术,打造无比美丽的世界!

TOP

#include <stdio.h> #include <string.h>

#define M 5 /*设一共有5个学生*/ #define N 6 /*设一个学生有六门课*/ typedef struct { float score[N]; int num; /*学生学号*/ }student; main() { int i,j,k; float total,sum; student a[M]; for(i=0;i<M;i++) { printf("please input the number of %d student:\n",i); scanf("%d",&a[i].num); printf("please input the i student score:\n",i); for(j=0;j<N;j++) scanf("%f",&a[i].score[j]); printf("\n"); }

for(i=0;i<M;i++) for(j=0;j<N;j++) if(a[i].score[j]<60) {printf("the student's number is:%d\n",a[i].num); printf("his score is:"); for(k=0;k<N;k++) {printf("%d",a[i].score[k]); sum+=a[i].score[k];} printf("the average is:\n",sum/N); } }

穷也要站在地主堆里 ! 不懂也要站在高手堆里 !

TOP

上面两位改的什么呀?运行了吗?当一个学生有多门课不及格时,输出多次,而且输出成绩全部是0

TOP

sum

必须初始化!!!

我 :“日本人也算人?” 上帝:“算,算,算吧。”。 我 :“这不是你的真心话。” 我 :“失手造批禽兽出来也就算了,但也不能把它们紧挨着咱中国人放啊!” 上帝:“你们中国人自己死好面子讲什么仁义,早点踏平过去,不早没事了。” 我 :。。。

TOP

有一门就够了

有一门就够了

TOP

我发现他们的跟我的一样,输入都有问题,还能改改吗

TOP

输入有问题是因为编译器的设计问题,本人在vc6.0中编译通过!

关于编译器的问题请看我的文章

http://bbs.bc-cn.net/bbs/dispbbs.asp?boardID=44&ID=9556&page=1

[此贴子已经被作者于2004-12-18 07:52:04编辑过]

我渴望掌控时空的核心——用最先进的技术,打造无比美丽的世界!

TOP

#define M 2 /*设一共有5个学生*/ #define N 3 /*设一个学生有六门课*/ typedef struct { float score[N]; int num; /*学生学号*/ }student; main() { int i,j,k; float total,sum; student a[M]; for(i=0;i<M;i++) { printf("please input the number of %d student:\n",i); scanf("%d",&a[i].num); printf("please input the i student score:\n",i); for(j=0;j<N;j++) scanf("%f",&a[i].score[j]);printf("\n"); }

for(i=0;i<M;i++) for(j=0;j<N;j++) if(a[i].score[j]<60) {printf("the student's number is:%d\n",a[i].num); printf("his score is:");sum=0; /*每次计算总分都要给sum赋0*/ for(k=0;k<N;k++) {printf("%f ",a[i].score[k]);/*成绩为float型,故要用%f */ sum+=a[i].score[k];} printf("the average is %f:\n",sum/N);/*此处少了%f*/ } }

TOP

sorry,我调试时把M,N改小了!

TOP

 14 12
发新话题