C 語言中的在方塊內部列印方塊程式


程式說明

按如下所示在方塊中列印方塊

演算法

Accept the number of rows the outer Square to be drawn
Display the Outer Square with the number of rows specified by the User.
Display another square inside the outer square.

示例

/* Program to print Square inside Square */
#include <stdio.h>
int main()
{
   int r, c, rows;
   clrscr();
   printf("Enter the Number of rows to draw Square inside a Square: ");
   scanf("%d", &rows);
   printf("
");    for (r = 1; r <= rows; r++){       for (c = 1; c <= rows; c++){          if ((r == 1 || r == rows || c == 1 || c == rows) || (r >= 3 && r <= rows - 2 && c >= 3 && c             <= rows - 2) && (r == 3 || r == rows - 2 || c == 3 || c == rows - 2)){                printf("#");          }          else{             printf(" ");          }       }       printf("
");    }    getch();    return 0; }

輸出

更新日期: 2020 年 1 月 9 日

794 人次瀏覽

開啟你的 職業

透過完成該課程獲得認證

開始
廣告
© . All rights reserved.