Wangdake - 2024年1月
type: channel
link: https://www.wangdake.top/index.php/2024/01/
description: After all, tomorrow is another day!
items: 菱形

菱形
type: item
date: 2024-01-29T18:30:00+08:00
description: #include <stdio.h> void print_diamond(int n) { int i, j, k; k = 2 * n - 1; for (i = 0; i < n; i++) { for (j = 1; j <= k; j++) { if (j >= n - i && j <= n + i) { printf("*"); } else { printf(" "); } } printf("\n"); } for (i = 1; i < n; i++) { for (j = 1; j <= k; j++) { if (j > i && j <= k - i) { printf("*"); } else { printf(" "); } } printf("\n"); } } int main(int argc, char *argv[]) { print_diamond(7); return 0; }