Write a program in C++ to print a string in reverse order. .

#include <iostream>
using namespace std;
void main()
{

 char str1[100], tmp;
   int l, lind, rind,i;

       cout<<"Print a string in reverse order:\n ";
     
   cout<<"Input a string to reverse : ";
   cin>>str1;
   l = strlen(str1);

   lind = 0;
   rind = l-1;
   
for(i=lind;i<rind;i++)
       {
       tmp = str1[i];
       str1[i] = str1[rind];
       str1[rind] = tmp;
       rind--;
   }

   cout<<"Reversed string is: "<< str1;

      cout<<endl;
         system ("pause");
}


Test Data :
Input a string to reverse : Welcome
Expected Output :
Reversed string is: emocleW
.

Write a program in C++ to print a string in reverse order. . Write a program in C++ to print a string in reverse order. . Reviewed by Unknown on June 20, 2017 Rating: 5

No comments:

Powered by Blogger.