【问题描述】 输入任意字符组成的一个字符串(长度<=100),将其反序输出。 【输入形式】 任意字符串 【输出形式】 字符串的反序 【样例输入】 This is a test. 【样例输出】 .tset a si sihT用C语言
时间: 2023-12-02 09:03:59 浏览: 54
好的,下面是用 C 语言编写的代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[101];
printf("请输入一个字符串:");
scanf("%s", str);
int len = strlen(str);
printf("反序输出的字符串为:");
for (int i = len - 1; i >= 0; i--) {
printf("%c", str[i]);
}
printf("\n");
return 0;
}
```
这段代码首先通过 `scanf` 函数获取用户输入的字符串,然后计算字符串长度,并通过循环输出反序后的字符串。例如,输入字符串 "This is a test.",则输出 ".tset a si sihT"。
相关问题
输入任意字符组成的一个字符串(长度<=100),将其反序输出。
好的,下面是用 C++ 语言编写的代码:
```c++
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string str;
cout << "请输入一个字符串:";
getline(cin, str);
reverse(str.begin(), str.end());
cout << "反序输出的字符串为:" << str << endl;
return 0;
}
```
这段代码首先通过 `getline` 函数获取用户输入的字符串,并使用 `reverse` 函数将字符串翻转,最后输出翻转后的字符串。例如,输入字符串 "Hello World!",则输出 "!dlroW olleH"。
输入任意字符组成的一个字符串(长度<=100),将其反序输出。用C语言
好的,下面是用 C 语言编写的代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[101];
printf("请输入一个字符串:");
scanf("%s", str);
int len = strlen(str);
printf("反序输出的字符串为:");
for (int i = len - 1; i >= 0; i--) {
printf("%c", str[i]);
}
printf("\n");
return 0;
}
```
这段代码首先通过 `scanf` 函数获取用户输入的字符串,然后计算字符串长度,并通过循环输出反序后的字符串。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)