练习7-11 字符串逆序 (15分)

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

输入格式:

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

输出格式:

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

输入样例:

Hello World!
 

输出样例:

!dlroW olleH

#include<stdio.h>
int main(void)
{
    char a[80];
    char string='0';
    int i=0;
    
    while(string!='\n'){
        scanf("%c",&string);
        a[i++]=string;
    }
    for(int j=i-2;j>=0;j--)            //a[n-1]存的是换行,回退。
        printf("%c",a[j]);
    
    return 0;
}


猜你喜欢

转载自www.cnblogs.com/Kimsohyun/p/12590634.html