使用 C 語言畫一個心形
#include <stdio.h>
void main() {
int i, j, k, l, m;
char c = 3;
for (i = 1; i <= 5; i ) printf("\n");
for (i = 1; i <= 3; i ) {
for (j = 1; j <= 32 - 2 * i; j ) printf(" ");
for (k = 1; k <= 4 * i 1; k ) printf("%c", c);
for (l = 1; l <= 13 - 4 * i; l ) printf(" ");
for (m = 1; m <= 4 * i 1; m ) printf("%c", c);
printf("\n");
}
for (i = 1; i <= 3; i ) {
for (j = 1; j <= 24 1; j ) printf(" ");
for (k = 1; k <= 29; k ) printf("%c", c);
printf("\n");
}
for (i = 7; i >= 1; i--) {
for (j = 1; j <= 40 - 2 * i; j ) printf(" ");
for (k = 1; k <= 4 * i - 1; k ) printf("%c", c);
printf("\n");
}
for (i = 1; i <= 39; i ) printf(" ");
printf("%c\n", c);
for (i = 1; i <= 4; i ) printf("\n");
}
依照心形,逐行在不同位置開始輸出不同數量的字符。
前5行為空行,後3行中間有空格來畫出心形頂部,再後3行等長,再後7行逐漸縮短,然後是一個單字符作為心形的尖,最後為4行空行。
Alt 3,在 Windows CMD 下是心形字符的 Alt 碼,printf("%c", 3) 輸出心形字符。
,