程序描述
弗洛伊德三角形是自然数的直角三角形数组,用于计算机科学教育。它以罗伯特·弗洛伊德的名字命名。它是通过用连续的数字填充三角形的行来定义的,从左上角的 1 开始
1 15 14 13 12 112 3 10 9 8 74 5 6 6 5 47 8 9 10 3 211 12 13 14 15 1Floyd's Triangle Reverse of Floyd's Triangle
算法
打印弗洛伊德三角形:
Accept the number of rows to print the Floyd’s TrianglePrint value 1 for the Row 1Print two values 2 and 3 in the next rowPrint three values 4, 5 and 6 in the next rowRepeat till the number of rows specified
要打印出弗洛伊德三角形的反向-
Accept the number of rows to print the reverse of Floyd’s TrianglePrint 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*/#includeint 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(""); for (r=1;r<=(rows*(rows+1))/2;r++){ printf("%d ",r); if(r==(c*(c+1))/2){ printf("
"); c++; } } printf("
立即学习“C语言免费学习笔记(深入)”;
"); /*Printing the Reverse of Floyd's Triangle*/ printf("Enter number of rows to print the reverse of Floyd's Triangle: "); scanf("%d",&revrows); printf("
立即学习“C语言免费学习笔记(深入)”;
"); printf("Reverse of Floyd's Triangle
"); printf("
立即学习“C语言免费学习笔记(深入)”;
"); d = (revrows*(revrows+1))/2; for(r1=revrows;r1>=1;r1--){ for(c1=r1;c1>=1;c1--,d--){ printf("%4d", d); } printf("
"); } getch(); return 0;}
输出

以上就是在C语言中编写一个打印反向Floyd三角形的程序的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444186.html
微信扫一扫
支付宝扫一扫