0026 编写一个函数,使从键盘上输入的一个字符串,按反序存放,并在主函数输出输入和输出该字符串


问题描述:

  编写一个函数,使从键盘上输入的一个字符串,按反序存放,并在主函数输出输入和输出该字符串。

代码展示:

 1 #include
 2 #include
 3 int main(){
 4     char str[100],str2[100];
 5     int len;
 6     int i,j;
 7     scanf("%s",str);
 8     len = strlen(str);
 9     for(i=0,j=len-1;i=0;i++,j--){
10         str2[i] = str[j];
11     }
12     printf("原始序列为:%s\n",str);
13     printf("逆序存放的序列为:%s\n",str2); 
14     return 0;
15 } 

运行截图:

相关