Fortran Coder

新手求教:关于数组的一个问题

查看数: 6405 | 评论数: 4 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2015-5-16 20:30

正文摘要:

!输入十个人的学号和成绩,高于平均分的学号和成绩打印出来 [Fortran] 纯文本查看 复制代码program yatou implicit none integer b(11) integer i,o,p,q,r,s,t o=0 p=0 q=0 r=0 s=0 do 10,i=1,10,1    re ...

回复

zlzshubao 发表于 2015-6-1 21:38:25
zlzshubao 发表于 2015-6-1 21:38
超级感谢!!麻烦你啦~

哈哈,棒!谢谢~
zlzshubao 发表于 2015-6-1 21:38:04
楚香饭 发表于 2015-5-16 20:58
最重要的是 Fortran 不支持连续判断 a

超级感谢!!麻烦你啦~
百事可乐 发表于 2015-5-17 10:18:24
用 count  函数不是很方便么?

[Fortran] 纯文本查看 复制代码
program yatou
implicit none

integer b(11)
integer i,o,p,q,r,s,t
o=0
p=0
q=0
r=0
s=0
do 10,i=1,10,1
   read*,b(i)
10 continue

do 20,i=1,10,1
     if(60>b(i)>0) then
     o=o+1
     endif
     if(59<b(i)<70) then
      p=p+1
     endif
     if(69<b(i)<80) then
     q=q+1
     endif
     if(79<b(i)<90) then
     r=r+1
     endif
     if(89<b(i)<100) then
     s=s+1
     endif
20 continue

print*,"不及格人数",o
print*,"60——69",p
print*,"70——79",q
print*,"80——89",r
print*,"90——100",s
end
楚香饭 发表于 2015-5-16 20:58:40
最重要的是 Fortran 不支持连续判断 a<b<c,必须写成 a<b.and.b<c
另外,也给了一些其他的修改意见。

[Fortran] 纯文本查看 复制代码
Program yatou
  Implicit None
  Integer :: b(10) !10个就够了
  Integer :: i, o = 0, p = 0, q = 0, r = 0, s = 0 !建议定义时给初值
  do i=1,10
    Read(*,*) b(i)
  end do!建议用 End Do
  !b = [ 68, 44, 5, 5, 5, 5, 6, 6, 7, 78 ]
  o = count( b<60.and.b>=0 )
  Print *, '不及格人数', o
  p = count( b<70.and.b>=60 )  
  Print *, '60——69', p
  q = count( b<80.and.b>=70 )
  Print *, '70——79', q
  r = count( b<90.and.b>=80 )
  Print *, '80——89', r
  s = count( b<=100.and.b>=90 )
  Print *, '90——100', s
End Program yatou

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-19 04:11

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表