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

王林
リリース: 2023-09-02 08:09:06
転載
1010 人が閲覧しました

プログラムの説明

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

正方形の中に埋め込まれた正方形を印刷するプログラムを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 までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!