Cプログラミング
 Computer >> コンピューター >  >> プログラミング >> Cプログラミング

Cの正方形の中に正方形を印刷するプログラム


プログラムの説明

以下に示すように、正方形の内側に正方形を印刷します

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("\n");
   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("\n");
   }
   getch();
   return 0;
}

出力

Cの正方形の中に正方形を印刷するプログラム


  1. Cプログラムの正方形の中の葉の面積?

    正方形の中の葉の面積を見つけるには、それをパーツに分割してパーツの面積を見つけ、次にその面積を追加して葉の面積を見つける必要があります。 面積を計算するために、葉を2つの部分に分割します。 第1部AECAの面積を求めるには、四角円AECDAの面積を求め、そこから三角形ACDAの面積を引きます。 象限の面積=1⁄4 *(π* r 2 )ここで π=22/7または3.141。 直角三角形の面積=1⁄2 * B *H=½a2 例 #include #define PI 3.14159265 int main() {    float a = 12.3; &n

  2. 正方形の中の葉の面積?

    ここでは、正方形ABCDの内側にある葉のような領域を取得する方法を説明します。正方形の各辺の長さは「a」です。 葉には2つの等しい部分があります。各部分の面積はpと言われ、今は- そして、完全な葉の面積は2pです。 例 #include <iostream> using namespace std; float leafArea(float a){    return (a * a * (3.1415/2 - 1)); } int main() {    float square_side = 7.0f;   &nb