逆フロイド三角形を出力するプログラムを C 言語で作成します。

WBOY
リリース: 2023-08-31 18:41:04
転載
1365 人が閲覧しました

プログラムの説明

フロイトの三角形は、コンピューター サイエンス教育で使用される自然数の直角三角形配列です。ロバート・フロイドにちなんで名付けられました。これは、三角形の行を左上隅の 1 から始まる連続した数字で埋めることによって定義されます。

1                               15 14 13 12 11
2 3                             10 9 8 7
4 5 6                         6 5 4
7 8 9 10                       3 2
11 12 13 14 15                 1
<strong>Floyd&#39;s Triangle                </strong><strong>Reverse of Floyd&#39;s Triangle</strong>
ログイン後にコピー

アルゴリズム

フロイトの三角形を印刷します:

Accept the number of rows to print the Floyd&rsquo;s Triangle
Print value 1 for the Row 1
Print two values 2 and 3 in the next row
Print three values 4, 5 and 6 in the next row
Repeat till the number of rows specified
ログイン後にコピー

フロイトの逆三角形を出力するには -

Accept the number of rows to print the reverse of Floyd&rsquo;s Triangle
Print the values in the reverse order as specified in the reverse of Floyd&rsquo;s Triangle
ログイン後にコピー

Example

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

Example

/*Program to print the Reverse of Floyd&#39;s Triangle*/
#include<stdio.h>
int main() {
   int r,c=1;
   int rows,revrows,r1,c1,d;
   clrscr();
   printf("Enter number of rows to print the Floyd&#39;s Triangle: ");
   scanf("%d", &rows);
   printf("</p><p>");
   for (r=1;r<=(rows*(rows+1))/2;r++){
      printf("%d ",r);
      if(r==(c*(c+1))/2){
         printf("</p><p>");
         c++;
      }
   }
   printf("</p><p></p><p>");
   /*Printing the Reverse of Floyd&#39;s Triangle*/
   printf("Enter number of rows to print the reverse of Floyd&#39;s Triangle: ");
   scanf("%d",&revrows);
   printf("</p><p></p><p>");
   printf("Reverse of Floyd&#39;s Triangle</p><p>");
   printf("</p><p></p><p>");
   d = (revrows*(revrows+1))/2;
   for(r1=revrows;r1>=1;r1--){
      for(c1=r1;c1>=1;c1--,d--){
         printf("%4d", d);
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}

ログイン後にコピー

Output

逆フロイド三角形を出力するプログラムを C 言語で作成します。

以上が逆フロイド三角形を出力するプログラムを C 言語で作成します。の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:tutorialspoint.com
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!