The program below is in fortran 95 I use http://www.compileonline.com to compile
ID: 3551822 • Letter: T
Question
The program below is in fortran 95 I use http://www.compileonline.com to compile it and I put the data below
in the input.txt
5
51
6
98
13
7
I see the output as:
program lab1
Integer :: Value, Counter, List_Len, Max, Min
Integer :: ary(99)
Open(Unit=5, File='input.txt', Access='SEQUENTIAL')
Read *, List_Len
Do Counter = 1, List_Len
Read *, ary(Counter)
End Do
close(5)
Counter=1
Max=ary(Counter)
Min=Max
Do Counter=1, List_Len
If(ary(Counter) > Max) Then
Max=ary(Counter)
End If
If(ary(Counter)<Min) Then
Min=ary(Counter)
End If
End do
Print *, 'Max Value is: ', Max
Print *, 'Lowest value is: ', Min
end program lab1
Explanation / Answer
I modified the code a little bit. Its working perfectly now :)
code:
program lab1
Integer :: Value, Counter, List_Len, Max, Min
Integer :: ary(99)
Open(Unit=5, File='input.txt', Access='SEQUENTIAL')
Read *, List_Len
Do Counter = 1, List_Len
Read *, ary(Counter)
End Do
close(5)
Counter=0
Max=ary(Counter)
Min=Max
Do Counter=1, List_Len
If(ary(Counter) > Max) Then
Max=ary(Counter)
End If
If(ary(Counter)<Min) Then
Min=ary(Counter)
End If
End do
Print *, 'Max Value is: ', Max
Print *, 'Lowest value is: ', Min
end program lab1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.