>  기사  >  백엔드 개발  >  역 플로이드 삼각형을 인쇄하는 프로그램을 C 언어로 작성하세요.

역 플로이드 삼각형을 인쇄하는 프로그램을 C 언어로 작성하세요.

WBOY
WBOY앞으로
2023-08-31 18:41:041361검색

프로그램 설명

프로이트의 삼각형은 컴퓨터 과학 교육에서 사용되는 자연수의 직각삼각형 배열입니다. 로버트 플로이드의 이름을 따서 명명되었습니다. 왼쪽 상단 모서리의 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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제