首页 > 后端开发 > C++ > 正文

在C语言中编写一个打印反向Floyd三角形的程序

WBOY
发布: 2023-08-31 18:41:04
转载
1452人浏览过

程序描述

弗洛伊德三角形是自然数的直角三角形数组,用于计算机科学教育。它以罗伯特·弗洛伊德的名字命名。它是通过用连续的数字填充三角形的行来定义的,从左上角的 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&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

的中文翻译为:

示例

/*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><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><span>立即学习</span>“<a href="https://pan.quark.cn/s/3851895a4c84" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">C语言免费学习笔记(深入)</a>”;</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><span>立即学习</span>“<a href="https://pan.quark.cn/s/3851895a4c84" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">C语言免费学习笔记(深入)</a>”;</p><p>");
   printf("Reverse of Floyd's Triangle</p><p>");
   printf("</p><p></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/3851895a4c84" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">C语言免费学习笔记(深入)</a>”;</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;
}

登录后复制

输出

在C语言中编写一个打印反向Floyd三角形的程序

以上就是在C语言中编写一个打印反向Floyd三角形的程序的详细内容,更多请关注php中文网其它相关文章!

全能打印神器
全能打印神器

全能打印神器是一款非常好用的打印软件,可以在电脑、手机、平板电脑等设备上使用。支持无线打印和云打印,操作非常简单,使用起来也非常方便,有需要的小伙伴快来保存下载体验吧!

下载
相关标签:
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号