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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: