Wednesday, June 14, 2017

Reverse String

Reverse String in C++

Here is the source code for C++ program that reverses the input string...

For example:  Input :"coder"
                      Output :"redoc"


Program

#include <iostream>
#include<cstdio>
using namespace std;

string FirstReverse(string str) {    //Function to reverse string
    
    string reverseString;

    for(long i = str.size() - 1;i >= 0; --i){
        reverseString += str[i];
    }

    return reverseString;

}

int main() {
string str;
cout<<"Enter some text: ";
    cin>>str;
    cout << FirstReverse(str)<<endl;   //function call
    return 0;

}



//int main portion can be written as: //As in coderbyte...

int main()
{
cout<<FirstReverse(gets(stdin))<<endl;

return 0;
}

Note: This is the first challenge program of coderbyte...
https://coderbyte.com


1 comment:

  1. Well explained string operation .
    there are good String program collection visit --->> Top String program

    ReplyDelete

Addition of two Binary numbers using C

Addition of two Binary numbers using C  The operation of adding two binary numbers is one of the fundamental tasks performed by a digita...