3/22/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

No comments:

Post a Comment