使用循环结构输出如下图形。 T-|||-×-|||-×××-|||-×××××-|||-×××××××-|||-回答案 ×××××-|||-习题3参考答案 ×××-|||-×
时间: 2023-12-27 18:03:13 浏览: 35
以下是使用循环结构输出图形的代码示例:
1. 输出T形图案:
```c
#include <stdio.h>
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 1 || j == (n / 2) + 1) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
}
return 0;
}
```
2. 输出倒三角形图案:
```c
#include <stdio.h>
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= n - i; j++) {
printf(" ");
}
for (int j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}
}
return 0;
}
```
3. 输出习题3参考答案图案:
```c
#include <stdio.h>
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
printf(" ");
}
for (int j = 1; j <= i; j++) {
printf("*");
}
printf("-");
for (int j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}
}
return 0;
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![](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)