reverse the string

//1st method

#include<iostream>
using namespace std;

void reverse(char a[],int start,int end)
{
char temp=a[start];
a[start]=a[end];
a[end]=temp;

start++;
end–;
if(start<end)
reverse(a,start,end);
}

main()
{
char a[50];
int i=0,count=0;
cout<<“\n enter the string to be reversed :”;
cin.get(a,50);
while(a[i]!=0)
{
count++;
i++;
}
i=0;
reverse(a,0,count-1);
cout<<a;

cout<<endl<<endl;
system(“pause”);

}

//2nd method

#include<iostream>

using namespace std;
main()
{
char a[300];
int i=0,count=0;
cout<<“\n enter the string :”;
cin.get(a,300);
cout<<“\n ur string is :”<<a;
while(a[i]!=”)
{
count++;
i++;
}
cout<<“\n length of the string is :”<<count<<endl;
cout<<“\n reverse of sentense is :”;
for(int j=count-1;j>=0;j–)
{ cout<<a[j]; }

cout<<endl<<endl<<endl;
system(“pause”);
}

//3rd methodĀ 

void ReverseString (char *String)

{

char *Begin = String;

char *End = String + strlen(String)1;

char TempChar;

while (Begin < End)
{
TempChar = *Begin;
*Begin = *End;
*End = TempChar;
Begin++;
End- -;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: