forked from miladsade96/FCS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter_reverse.f90
More file actions
26 lines (24 loc) · 823 Bytes
/
character_reverse.f90
File metadata and controls
26 lines (24 loc) · 823 Bytes
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
! Created By EverLookNeverSee@GitHub on 5/11/20
! this function takes an arbitrary sized character and reverse it.
function character_reverse(ch) result(res)
! declaring dummy parameters
character (len=*) :: ch, res
! declaring inside variables
integer :: i, it, length
length = len(ch)
do i = 1, length
it = length - i + 1 ! reading character from the right
res(i:i) = ch(it:it)
end do
res = adjustl(res)
end function character_reverse
program main
! declaring variables
character (len=5) :: user_input, result, character_reverse
! getting user input character
print *, "Enter a character(len=5):"
read *, user_input
! calling character_reverse function
result = character_reverse(user_input)
print *, "result:", result
end program main