字符串逆序

输入一个字符串,对该字符串进行逆序,输出逆序后的字符串。

输入格式:

输入在一行中给出一个不超过80个字符长度的、以回车结束的非空字符串。

输出格式:

在一行中输出逆序后的字符串。

输入样例:
Hello World!
输出样例:
!dlroW olleH

#include<stdio.h>

int main(){
  char s[81]={0};
  //char c;
  int i=0;
  do{
    scanf("%c",&s[i++]);
    /*if(c!='
'){
      s[i++]=c;
    }*/
  }while(s[i-1]!='
');
  i=i-2;//回车要占用两个字符
  while(i>=0){
    printf("%c",s[i--]);
    //i--;
  }
  printf("
");
  return 0;
} 
  1. #include<stdio.h>   
  2. #include<string.h>   
  3. int main()  
  4. {  
  5.     char str1[81], str2[82];  
  6.     gets(str1);  
  7.     for (int i = strlen(str1) - 1; i >= 0; i--)  
  8.     {  
  9.         str2[strlen(str1) - 1 - i] = str1[i];  //字符数组另存
  10.     }  
  11.     str2[strlen(str1)] = '';  
  12.     puts(str2);  
  13.     return 0;  
  14. }  
原文地址:https://www.cnblogs.com/emochuanshuo/p/3918639.html