Reverse Every Word

The program must accept a string S containing multiple words as the input. The program must reverse every word in the string S. Then the program must print the modified string S as the output.

Input : Friday and Saturday

Output : yadirF dna yadrutaS

Explanation:
After reversing every word in the string Friday and Saturday, the string becomes yadirF dna yadrutaS.
Hence the output is yadirF dna yadrutaS

Here are the various methods and logic.

Python :

IMG 20200418 WA0000 1
# Code by @ Agent Stark
Screenshot 594
# Code by @ Agent Parker
# Code by @ Agent Hawkeye
s=input().strip()
words=s.split(' ')
for ele in words:
    newword=ele[::-1]
    n=''.join(newword)
    print(n,end=" ")

C :

Screenshot 445
# Code by @ Agent Marvel
Screenshot 16
# Code by @ Agent Natasha
Previous Article

Check Sorted Array - Descending Order

Next Article

Expand String - K Characters

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *