ホームページ  >  記事  >  バックエンド開発  >  正方形の中に埋め込まれた正方形を印刷するプログラムをC言語で書いてください。

正方形の中に埋め込まれた正方形を印刷するプログラムをC言語で書いてください。

王林
王林転載
2023-09-02 08:09:06994ブラウズ

プログラムの説明

以下に示すように、別の四角形の中に四角形を印刷します

正方形の中に埋め込まれた正方形を印刷するプログラムを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.

の中国語訳例

は:

Example

/* 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("</p><p>");
   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("</p><p>");
   }
   getch();
   return 0;
}

出力

正方形の中に埋め込まれた正方形を印刷するプログラムをC言語で書いてください。

以上が正方形の中に埋め込まれた正方形を印刷するプログラムをC言語で書いてください。の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。