String Programming, String, C++ String
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

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: