-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaas.f90
37 lines (36 loc) · 1.07 KB
/
aas.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
! Created by EverLookNeverSee@GitHub on 5/25/20.
! This program sorts a sequence in ascending order.
program aas
implicit none
! declaring variables
integer :: n, i, j
real :: temp
real, allocatable, dimension(:) :: sequence
! getting user input in order to specify number of elements in sequence.
n = -1
do
print *, "Enter the number of elements in the sequence:"
read *, n
if (n > 0) exit
end do
! allocating memory for array
allocate(sequence(n))
! getting elements of sequence from user input
do i = 1, n
print *, "Element number", i, "is:"
read *, sequence(i)
end do
! Compare two elements sequence(i) and sequence(j) (i < j).
! If a i > a j swap the two elements.
do i = 1, n - 1
do j = i + 1, n
if (sequence(i) > sequence(j)) then
temp = sequence(j)
sequence(j) = sequence(i)
sequence(i) = temp
end if
end do
end do
! printing sorted sequence.
print *, sequence
end program aas