24小时热门版块排行榜    

查看: 1096  |  回复: 1

crrcrr

新虫 (初入文坛)

[求助] Fortran循环语句,运行不出来,求大神赐教!!! 已有1人参与

题目是输入100名学生的学号和五门课的成绩,要求统计并打印出总分成绩最高学生的学号、各门课成绩、总成绩及平均成绩。我先编了一个5名学生和五门课成绩的。程序如下:
open(10,file='data')
open(20,file='out')
read(10,*)
write(20,100)
100 format(1x,"学号 数学 物理 化学 生物 英语 总成绩 平均成绩"
do i=1,5,1
read(10,*)x,m,p,c,b,e
enddo
max=0
do i=1,5,1
   t=m+p+c+b+e
   if(t>max)then
   max=t
   endif
enddo
a=max/5
write(20,200)x,m,p,c,b,e,max,a
200 format(i4,5f6.1,2f8.1)
end
然后准备的data文件是这样的:
5  5
1  80.0  68.0  98.0  69.0  65.0
2  96.0  78.0  96.0  77.0  82.0
3  78.0  80.0  80.0  89.0  75.0
4  68.0  96.0  78.0  91.0  88.0
5  98.0  98.0  68.0  94.0  100.0
编译没问题,但是运行的时候显示run-time error F6101(data)-invaild integer
不知道哪错了
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

fish.yfyh

铜虫 (小有名气)

【答案】应助回帖

★ ★ ★ ★ ★
感谢参与,应助指数 +1
crrcrr: 金币+5, ★★★★★最佳答案, 谢谢~ 2014-05-26 12:06:23
代码如下,仅供参考
program test
implicit none
integer :: i,x(5),id(1)
real(8) :: score(5,5),all_score(5),ave_score(5)

open(10,file='data')
open(20,file='out')
read(10,*)
write(20,100)
100 format(1x,"学号 数学 物理 化学 生物 英语 总成绩 平均成绩"
do i=1,5,1
  read(10,*) x(i),score(i,
  all_score(i) = sum(score(i,)
  ave_score(i) = all_score(i) / 5
enddo
id = maxloc(all_score)
write(20,'(i4,5f6.1,2f8.1)') id(1),score(id(1),,all_score(id(1)),ave_score(id(1))

stop
end program
结果如下
学号 数学 物理 化学 生物 英语 总成绩 平均成绩
   5  98.0  98.0  68.0  94.0 100.0   458.0    91.6
2楼2014-05-26 01:28:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 crrcrr 的主题更新
信息提示
请填处理意见