zlzshubao 发表于 2015-6-1 21:38 哈哈,棒!谢谢~ |
楚香饭 发表于 2015-5-16 20:58 超级感谢!!麻烦你啦~ |
|
用 count 函数不是很方便么? [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode 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 |
|
最重要的是 Fortran 不支持连续判断 a<b<c,必须写成 a<b.and.b<c 另外,也给了一些其他的修改意见。 [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode 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, 2025-10-24 09:49