-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Monday, 29 June 2015

Reversal of string


Lets play a game !!!!

Write your name in reverse order.

Ok wait,let me write my name first.

Khawaja

Reversed: ajawahK

Isn't it interesting?

So,today I am here with an interesting program that will input a string from the user and then display its reverse.

Have a look at its source code.

Source code

#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
main()
{
char abc[20];
cout<<"Enter any string:";
gets(abc);
int len=strlen(abc); //used to find the string length
for(int i=len-1;i>=0;i--) //reverse loop
cout<<abc[i];
return 0;
getch();
}


Output

Reversal of string
Reversal of string

No comments:

Post a Comment