Write a Program in C++ & Python to Reverse a String

By | August 27, 2019

In this program, we will ask the user to enter a string and print out that string in reverse order.

C++ program to reverse a string:

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main() {
     clrscr();
     char ch[50];
     cout<<"Enter a String: ";
     cin>>ch;
     cout<<"The reverse string is: ";
     for(int i=strlen(ch); i >= 0;i--)
         cout<<ch[i];
     getch();
}

Output:

Enter a String: tech
The reverse string is: hcet

Python program to reverse a string:

ch= input("Enter a String: ")
print("The reverse string is:",ch[::-1])

Output:

Enter a String: techgeekbuzz
The reverse string is: zzubkeeghcet

Leave a Reply

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