首页
/
每日頭條
/
科技
/
寫出自己畫的小迷宮的c語言代碼
寫出自己畫的小迷宮的c語言代碼
更新时间:2025-12-03 02:28:41

使用 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"); }

寫出自己畫的小迷宮的c語言代碼(趣味代碼-用)1

依照心形,逐行在不同位置開始輸出不同數量的字符。

前5行為空行,後3行中間有空格來畫出心形頂部,再後3行等長,再後7行逐漸縮短,然後是一個單字符作為心形的尖,最後為4行空行。

Alt 3,在 Windows CMD 下是心形字符的 Alt 碼,printf("%c", 3) 輸出心形字符。

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2025 - www.tftnews.com All Rights Reserved