用c语音输入两个字符,输出用这两个字符绘制的三角形;
时间: 2023-04-01 07:03:24 浏览: 154
您好,可以使用以下代码实现:
#include <stdio.h>
int main() {
char c1, c2;
printf("请输入两个字符:\n");
scanf("%c %c", &c1, &c2);
printf(" %c\n", c1);
printf(" %c%c%c\n", c1, c2, c1);
printf("%c%c%c%c%c\n", c1, c2, c2, c2, c1);
return ;
}
输入两个字符后,程序会输出一个由这两个字符绘制的三角形。希望能帮到您。
相关问题
用C语音输入一个字符串输出反序的字符串
以下是用C语言实现输入一个字符串输出反序的字符串的代码示例:
```c
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int i, len;
printf("请输入一个字符串:");
gets(str);
len = strlen(str);
for(i = len - 1; i >= 0; i--)
{
printf("%c", str[i]);
}
return 0;
}
```
c语音连接两个字符串
在C语言中,连接两个字符串可以使用字符串拼接的方式。C语言提供了一个库函数`strcat()`来实现字符串的连接操作。
`strcat()`函数的原型如下:
```c
char* strcat(char* destination, const char* source);
```
该函数接受两个参数,`destination`和`source`,分别表示目标字符串和要连接的字符串。`strcat()`函数会将`source`字符串的内容追加到`destination`字符串的末尾,并返回连接后的字符串。
以下是一个示例代码,演示了如何使用`strcat()`函数连接两个字符串:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str1[50] = "Hello";
char str2[] = " World!";
strcat(str1, str2);
printf("连接后的字符串: %s\n", str1);
return 0;
}
```
输出结果为:
```
连接后的字符串: Hello World!
```