I have been trying to run the code which arrange the array in decreasing order. The array is takem from the input file and then arranged goed into the output file. The code compiles fine, but when i run a.exe it shows an error. Here is the code:
program arrangingARRAY
dimension a(100)
open(1,file="array.txt")
read(1,*) n
do i =1, n
read(1,*) a(i)
enddo
close(1)
i=1
1 continue
j=i+1
2 continue
if (a(j).lt.a(i)) then
goto 3
else
s=a(i)
a(i)=a(j)
a(j)=s
end i
3 continue
j=j+1
if (j.le.n) then
goto 2
else
i=i+1
end if
if (i.lt.n) then
goto 1
end if
open(1,file="decreasingARRAY.txt")
do i=1,n
write(1,*) a(i)
enddo
end
the input file looks like this:
60
123
60
21
1
2
3
4
11
90
I have tried to put the empty line into the txt file, but it doesn`t work. If you have any solutions to this problem, please help.
read(1,*) n
and then proceed to readn
numbers from the file. Does the input file have 60 entries?