程序描述
弗洛伊德三角形是自然数的直角三角形数组,用于计算机科学教育。它以罗伯特·弗洛伊德的名字命名。它是通过用连续的数字填充三角形的行来定义的,从左上角的 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's Triangle </strong><strong>Reverse of Floyd's Triangle</strong>
算法
打印弗洛伊德三角形:
Accept the number of rows to print the Floyd’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’s Triangle Print the values in the reverse order as specified in the reverse of Floyd’s Triangle
Example
的中文翻译为:
示例
/*Program to print the Reverse of Floyd'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's Triangle: ");
scanf("%d", &rows);
printf("<p>");
for (r=1;r</p>
<p>");
c++;
}
}
printf("</p>
<p></p>
<p>");
/*Printing the Reverse of Floyd's Triangle*/
printf("Enter number of rows to print the reverse of Floyd's Triangle: ");
scanf("%d",&revrows);
printf("</p>
<p></p>
<p>");
printf("Reverse of Floyd'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;
}
</p></stdio.h>
输出

13万字C语言保姆级教程(深入):立即使用
在学习笔记中,你将探索c语言的核心概念和高级技巧!











