Tuesday, 22 March 2016

C++ Program to Display String From Backward

Problem:- C++ Program to Display String From Backward or Write A C++ Program To Display String From Backward or C++ program to Reverse a String or C++ Program to Reverse String or Display A String Backwards in c++ or c++ - Printing input string words in reverse order or Loop to print string backward or printing a string backwards or Displaying an input backwards or How can I print a string backwards? or Different methods to reverse a string in C/C++ or Write a program to reverse an array or string.

Explanation:- Reading a string form backward is similar to reverse the string here I use a For Loop for finding the length of the string or we can use string.length() function depend upon your choice. After calculating the size of the string with the second For Loop printing the string from last-1 index to greater or equal to zero indexes. this is a simple way for reading a string from backward or we can use a simple inbuilt function for made program easier but using an inbuilt library function for beginners is not a good practice. First beginners know how they can build a logic and implement the existing problem after that for saving the time and space beginners can use an inbuilt library function.


Solution:-

#include<iostream>
using namespace std;

int main()
{
/*Visit - www.programmingwithbasics.com*/
   
    printf("=====================================");
    printf("\nVisit - www.programmingwithbasics.com");
    printf("\n=====================================");

    char str[80];
  int l, i;
    
cout<<"\n\nEnter a String: ";
    cin.getline(str, 80);
    for(l = 0; str[l] != '\0'; l++);// finding the length of a string
    
    cout<<"\n\nString From Backward is below\n\n";
    
    for(i = l - 1; i >= 0; i--)
    {
        cout << str[i];
    }   
    return 0;
}

Output:-

C++ Program to Display String From Backward



You May Also See


1. C++Program To Calculate Factorial Of A Given Number Using Loop

2. C++ Program To Print A Message Multiple Times Using Loop

3. C++ Program To Print A Table Of Given Number Using Loop

4. C Program For Calculator Using Switch Case

5. Java Program To Check Number Is Positive Or Negative

6. Java Program To Find Character Is Vowel Or Not

7. C Program For Find A Grade Of Given Marks Using Switch Case

8. C Program For Finding Radius Circumference Using Switch Case

9.C Program For Remove All Vowels From A String Using Switch Case

10. C++ Program To Print A Reverse Order Of Any Number Using Loop

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment