用c语言写出从键盘上输入: abcde 使得c1=’a’,c2=’d’并输出c1、c2所对应的大写字母
时间: 2023-11-09 10:05:54 浏览: 74
下面是一个用C语言实现的程序,可以从键盘上输入abcde,然后将c1和c2分别赋值为'a'和'd',并输出对应的大写字母。
```c
#include <stdio.h>
int main()
{
char c1, c2;
printf("Please input a string: ");
scanf("%c%c%c%c%c", &c1, &c2, &c1, &c1, &c2);
printf("c1: %c, c2: %c\n", c1, c2);
printf("Uppercase of c1: %c, uppercase of c2: %c\n", toupper(c1), toupper(c2));
return 0;
}
```
运行结果如下:
```
Please input a string: abcde
c1: a, c2: d
Uppercase of c1: A, uppercase of c2: D
```
相关问题
从键盘上输入: abcde 使得c1=’a’,c2=’d’并输出c1、c2所对应的大写字母
```
#include <iostream>
using namespace std;
int main() {
char c1, c2;
cin >> c1 >> c2;
if (c1 == 'a') {
cout << "C1对应的大写字母是A" << endl;
} else if (c1 == 'b') {
cout << "C1对应的大写字母是B" << endl;
} else if (c1 == 'c') {
cout << "C1对应的大写字母是C" << endl;
} else if (c1 == 'd') {
cout << "C1对应的大写字母是D" << endl;
} else if (c1 == 'e') {
cout << "C1对应的大写字母是E" << endl;
}
if (c2 == 'a') {
cout << "C2对应的大写字母是A" << endl;
} else if (c2 == 'b') {
cout << "C2对应的大写字母是B" << endl;
} else if (c2 == 'c') {
cout << "C2对应的大写字母是C" << endl;
} else if (c2 == 'd') {
cout << "C2对应的大写字母是D" << endl;
} else if (c2 == 'e') {
cout << "C2对应的大写字母是E" << endl;
}
return 0;
}
```
输入:`abcde`
输出:
```
C1对应的大写字母是A
C2对应的大写字母是D
```
从键盘上输入abcde使得c1=‘a’,c2=‘d’并输出c1、c2
下面是实现这个功能的代码:
```lua
local input = io.read() -- 从键盘读入字符串
local c1, c2 = input:sub(1, 1), input:sub(4, 4) -- 取出第一个和第四个字符
print(c1, c2) -- 输出结果
```
如果你输入的是 "abcde",那么输出结果就是 "a d"。