c++编写函数实现一个字符串的逆序。在主函数中输入字符串,调用函数将字符串逆序,而后输出。

如题所述

#include
using namespace std;
void rev(char s[])
{char *p,*q,c;
for(p=s;*p;p++);
for(q=s,--p;q<p;)
{c=*p;*p--=*q;*q++=c;}
}
int main()
{ char s[100];
cin.getline(s,100);
rev(s);
cout<<s<<endl;
return 0;
}

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答