Program to Reverse a String in Python and C Programming

Posted in

Program to Reverse a String in Python and C Programming
vinaykhatri

Vinay Khatri
Last updated on December 22, 2024

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

    Program to reverse a string in C++

    #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

    Program to reverse a string in Puthon:

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

    Output:

    Enter a String: techgeekbuzz
    The reverse string is: zzubkeeghcet

    People are also reading:

    Leave a Comment on this Post

    0 Comments