如果txt中数据是一个数据一行,txt文件名是1.txt的情况下:
program abc
implicit none
integer i
integer j[18]
logical var
open(unit=1,file='1.txt')
j=0
do while(.true.)
read(1,*,iostat=var) i
select case(i)
case(1)
j(1)=j(1)+1
case(2)
j(2)=j(2)+1
case(3)
j(3)=j(3)+1
case(4)
j(4)=j(4)+1
......! 把5-17的依次补齐
case(18)
j(18)=j(18)+1
end select
!得到的数组j表示数据为1,2...18时的个数,分别对应j[1],j[2]...j[18],再根据你的需要进行输出就行了
if(var/=0)exit
enddo
温馨提示:答案为网友推荐,仅供参考