Qn: Write a C++ program to reverse a given string
-By Admin, Last Update On 31st May,2019 12:53 am
#include<iostream>
#include<string.h>
using namespace std;
int main () {
   char mystring[30] = "Thomas Edison";
   int length=strlen(mystring);
   int i;
   char temp;
   for(i=0;i<length/2;i++){
    temp=mystring[i];
    mystring[i]=mystring[(length-1)-i];
    mystring[(length-1)-i]=temp;
   }
  cout<<"Reversed String is: "<<endl<<mystring;
   return 0;
  }

Output:

Reversed String is:
nosidE samohT

Pgcomments

Comments