用C语言打印* *\n*** ***\n**** ****\n***********\n**** ****\n*** ***\n* *\n
时间: 2023-12-04 22:41:41 浏览: 28
C语言程序设计-编写程序打印*菱形 * *** ***** *******
以下是用C语言打印* *\n*** ***\n**** ****\n***********\n**** ****\n*** ***\n* *\n的代码实现:
```c
#include <stdio.h>
int main() {
int i, j, k, n = 4;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n - i; j++) {
printf(" ");
}
for (k = 1; k <= 2 * i - 1; k++) {
printf("*");
}
printf(" ");
for (k = 1; k <= 2 * (n - i) - 1; k++) {
printf(" ");
}
for (k = 1; k <= 2 * i - 1; k++) {
printf("*");
}
printf("\n");
}
for (i = n - 1; i >= 1; i--) {
for (j = 1; j <= n - i; j++) {
printf(" ");
}
for (k = 1; k <= 2 * i - 1; k++) {
printf("*");
}
printf(" ");
for (k = 1; k <= 2 * (n - i) - 1; k++) {
printf(" ");
}
for (k = 1; k <= 2 * i - 1; k++) {
printf("*");
}
printf("\n");
}
return 0;
}
```
阅读全文