I have to create a program that reverses phrases.
For example: when I write hello guys, I want syug olleh
This is what
One simple way to do it ...
character(80) :: string = "Whatttt's up doc?"
character :: temp
integer :: i, length
write (*,*) string ! Writes it out proper.
length = len_trim(string) ! ignores trailing blanks.
! use len(string) to reverse those as well
do i = 1, length/2
temp = string(i:i)
string(i:i) = string(length+1-i:length+1-i)
string(length+1-i:length+1-i) = temp
end do
write(*,*) string ! Writes it out backwards.
end
Others will come up with more intelligent ones (and shorter) for sure.