用getchar函数输入3个字符,编程实现用printf函数按输入次序输出这3个字符,并输出这三个字符的ASCII码值,最后用putchar函数按与输入字符相反的次序输出这三个字符
时间: 2024-02-24 16:54:14 浏览: 167
好的,以下是实现代码:
```c
#include <stdio.h>
int main() {
char c1, c2, c3;
printf("请输入三个字符:\n");
c1 = getchar(); // 获取第一个字符
c2 = getchar(); // 获取第二个字符
c3 = getchar(); // 获取第三个字符
printf("您输入的字符为:%c%c%c\n", c1, c2, c3);
printf("它们的ASCII码值分别为:%d %d %d\n", c1, c2, c3);
printf("按相反的次序输出这三个字符:\n");
putchar(c3); // 输出第三个字符
putchar(c2); // 输出第二个字符
putchar(c1); // 输出第一个字符
return 0;
}
```
运行程序,输入三个字符后,即可看到输出结果:
```
请输入三个字符:
abc
您输入的字符为:abc
它们的ASCII码值分别为:97 98 99
按相反的次序输出这三个字符:
cba
```
相关问题
用getchar函数输入3个字符,编程实现用printf函数按输入次序输出这3个字符,并输出这3个字符的ASCII码值,最后用putchar函数按与输入字符相反的次序输出这3个字符
我可以回答这个问题。以下是代码实现:
#include <stdio.h>
int main() {
char c1, c2, c3;
printf("请输入3个字符:\n");
c1 = getchar();
c2 = getchar();
c3 = getchar();
printf("您输入的字符是:%c%c%c\n", c1, c2, c3);
printf("它们的ASCII码值分别是:%d %d %d\n", c1, c2, c3);
printf("按相反的次序输出这3个字符:");
putchar(c3);
putchar(c2);
putchar(c1);
return ;
}
用getchar函数输入3个自字符,编程实现用printf函数按输入次序输出这三个字符,并输出这3个字符的ascll码值,最后用putchar函数按与输入字符相反的次序输出这三个字符
```c
#include <stdio.h>
int main() {
char c1, c2, c3;
printf("Please enter three characters: ");
c1 = getchar();
c2 = getchar();
c3 = getchar();
printf("The characters you entered are: %c %c %c\n", c1, c2, c3);
printf("Their ASCII codes are: %d %d %d\n", c1, c2, c3);
printf("The characters in reverse order are: ");
putchar(c3);
putchar(c2);
putchar(c1);
printf("\n");
return 0;
}
```
示例输出:
```
Please enter three characters: abc
The characters you entered are: a b c
Their ASCII codes are: 97 98 99
The characters in reverse order are: cba
```
阅读全文