用C语言完成:从键盘输入一个字符串,将其按逆序输出
时间: 2024-05-06 16:19:03 浏览: 107
c语言逆序输出字符串
```c
#include<stdio.h>
#include<string.h>
int main()
{
char str[50], rev[50];
int i, j, len;
printf("Enter a string: ");
scanf("%s", str);
len = strlen(str);
j = 0;
for(i = len - 1; i >= 0; i--)
{
rev[j++] = str[i];
}
rev[j] = '\0';
printf("Reverse of the string: %s", rev);
return 0;
}
```
输出结果:
```
Enter a string: Hello World
Reverse of the string: dlroW olleH
```
阅读全文