#include<iostream>
using namespace std;
void revstr(char [][30],int);
int main()
{
int m,i;
char a[15][30];
cout<<"Enter number of strings: ";
cin>>m;
cout<<"\nEnter the strings :\n\n";
for(i=0;i<=m;++i)
{
cin.getline(a[i],30);
}
cout<<"\n\nThe strings are:\n\n";
for(i=0;i<=m;++i)
{
cout<<a[i]<<"\n";
}
revstr(a,m);
cout<<"The reversed strings are :\n\n";
for(i=0;i<=m;++i)
{
cout<<a[i]<<"\n";
}
return 0;
}
void revstr(char a[][30],int m)
{
int i,j,k,len;
char temp;
for(i=0;i<=m;++i)
{
len=strlen(a[i]);
for(j=0,k=len-1;j<len/2;++j,--k)
{
temp=a[i][j];
a[i][j]=a[i][k];
a[i][k]=temp;
}
}
}
using namespace std;
void revstr(char [][30],int);
int main()
{
int m,i;
char a[15][30];
cout<<"Enter number of strings: ";
cin>>m;
cout<<"\nEnter the strings :\n\n";
for(i=0;i<=m;++i)
{
cin.getline(a[i],30);
}
cout<<"\n\nThe strings are:\n\n";
for(i=0;i<=m;++i)
{
cout<<a[i]<<"\n";
}
revstr(a,m);
cout<<"The reversed strings are :\n\n";
for(i=0;i<=m;++i)
{
cout<<a[i]<<"\n";
}
return 0;
}
void revstr(char a[][30],int m)
{
int i,j,k,len;
char temp;
for(i=0;i<=m;++i)
{
len=strlen(a[i]);
for(j=0,k=len-1;j<len/2;++j,--k)
{
temp=a[i][j];
a[i][j]=a[i][k];
a[i][k]=temp;
}
}
}
0 comments:
Post a Comment