Write a C++ program to display string from backward.
Note: Here we use cin.getline(string_name, string_size) function for input string from the user.
#include<iostream>
using namespace std;
int main( )
{
int i, j;// loop variable
int length = 0; //to hold length of string
char name[30];
cout<<"Enter string to displayed from backward : ";
cin.getline(name, 30);
for(i = 0; name[i] != '\0'; i++)
{
length = length +1;
}
cout<<"String displayed from backward : ";
for(int j = length - 1; j>= 0; j--)
{
cout << name[j];
}
return 0;
}
Program output is tested on www.jdoodle.com
Output:
Enter string to displayed from backward : Mukesh Rajput
String displayed from backward : tupjaR hsekuM
Thanks
Mukesh Rajput
Thanks
Mukesh Rajput
Post A Comment:
0 comments: