C++ Program:

- To reverse a string

Example:

User Input: Hello World

Output: dlroW olleH

#include <iostream>
using namespace std;

int main() {

  string s1,reverse;
  cout<<"Enter your string : ";
  getline(cin,s1);
  int l=s1.length()-1;
  
  while(l!=-1) {
    reverse+=s1[l--];
  }
  cout<<"Your reversed string : "<<reverse;
  return 0;
}

Output:

  Enter Your string : fun with code
  Your reversed string : edoc htiw nuf
Program
string

Main Logic :

// varibale 'l' holds length of string - 1 (since index starts from 0)
while(l!=-1) {
  reverse+=s1[l--];
}
Concept

Coming Soon !

Quick
Tutorial

Quote

Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.