Q:

C++ Program to Display String From Backward

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;

int main()
{
    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:

Enter a String: nerdutella

String From Backward is below

alletudren

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program to Count Number of Words (Words Counte... >>
<< C++ Program to Copy One String into Another String...