Write a C++ program to reverse a string, where string is entered by the user.
Program Code:
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char str[100], temp;
int i=0, j;
cout<<"Enter the string to reverse : ";
cout<<endl;
gets(str);
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
cout<<"Reverse of the given string is : ";
cout<<str;
return 0;
}
The program output is tested on www.jdoodle.com
Output:
Enter the string to reverse : Mukesh Rajput
Reverse of the given string is : tupjaR hsekuM
Thanks
Mukesh Rajput
Post A Comment:
0 comments: