C++—— 字符串正反连接

字符串正反连接

 

需求如下:

 

 

 

代码如下:

 

 

 1 #include <iostream>
 2 #include <stdio.h>  //这一行其实没有什么用
 3 #include <string.h>
 4 using namespace std;
 5 int main()
 6 {
 7     char c[50]; 
 8     int n=0;
 9     gets(c);  //从这里获取字符串
10     cout<<c;  //获取了的字符串就是正序,就立马进行输出
11     n=strlen(c);  //用strlen函数测量字符串的长度,需包含<string.h>
12     for(int i=n-1;i>=0;i--){ //从数组最后一个数,开始遍历数组,进行输出
13         cout<<c[i];
14     }
15     return 0;
16  } 

 

写在最后:

  哪里有不足或者错误的地方,欢迎小伙伴们进行指教,一起进步哦!

posted @ 2020-09-09 09:50  闫佳杰  阅读(712)  评论(0)    收藏  举报