ホームページ  >  記事  >  バックエンド開発  >  C 言語で中実および中空のダイヤモンド パターンを印刷するプログラムを作成します。

C 言語で中実および中空のダイヤモンド パターンを印刷するプログラムを作成します。

WBOY
WBOY転載
2023-08-29 09:33:14991ブラウズ

プログラムの説明

以下に示す中実および中空のダイヤモンド パターンを印刷します

C 言語で中実および中空のダイヤモンド パターンを印刷するプログラムを作成します。

アルゴリズム

中空の場合Rhombus-

Accept the Number of Rows for Hollow Rhombus from the User
Create a Hollow Rhombus containing the same number of Rows specified by the User.
Print the first row containing the number of stars same as the number of rows.
Print the second row containing the first and last star as show in the output and leave the spaces between first and the last star.
Do the same till you reach the last Row.
Print the last row containing the number of stars same as the number of rows.

Solid Rhombus の場合 -

Accept the Number of Rows for Solid Rhombus from the User
Create a Solid Rhombus containing the same number of Rows specified by the User.
Print the first row containing the number of stars same as the number of rows.
Do the same till you reach the last Row.

Example

の中国語翻訳は次のとおりです:

Example

/* Program to print Hollow and Solid Rhombus star pattern */
#include <stdio.h>
int main() {
   int r, c, rows; //Hollow Rhombus
   int r1,c1, rows1; //Solid Rhombus
   clrscr();
   printf("Enter the Number of rows for Hollow Rhombus Pattern: ");
   scanf("%d", &rows);
   printf("</p><p>");
   for(r=1; r<=rows; r++){
      for(c=1; c<=rows-r; c++){
         printf(" ");
      }
      for(c=1; c<=rows; c++){
         if(r==1 || r==rows || c==1 || c==rows)
         printf("*");
         else
         printf(" ");
      }
      printf("</p><p>");
   }
   printf("</p><p>");
   printf("Enter the Number of rows for Solid Rhombus Pattern: ");
   scanf("%d", &rows1);
   printf("</p><p>");
   for (r1=1; r1<=rows1; r1++){
      for (c1=1; c1<=rows1-r1;c1++){
         printf(" ");
      }
      for (c1=1; c1<=rows1; c1++){
         printf("*");
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}

出力############

以上がC 言語で中実および中空のダイヤモンド パターンを印刷するプログラムを作成します。の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

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