
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Program to print Reverse Floyd’s triangle in C
Program Description
Floyd's triangle is a right-angled triangular array of natural numbers, used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner
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 Floyd's Triangle Reverse of Floyd's Triangle
Algorithm
To print the Floyd’s Triangle −
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
To print the reverse of Floyd’s Triangle −
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("
"); for (r=1;r<=(rows*(rows+1))/2;r++){ printf("%d ",r); if(r==(c*(c+1))/2){ printf("
"); c++; } } printf("
"); /*Printing the Reverse of Floyd's Triangle*/ printf("Enter number of rows to print the reverse of Floyd's Triangle: "); scanf("%d",&revrows); printf("
"); printf("Reverse of Floyd's Triangle
"); printf("
"); 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; }
Output
- Related Articles
- Java Program to Display Floyd's Triangle
- Floyd's triangle in PL/SQL
- Java program to print Pascal's triangle
- Java Program to Print Star Pascal's Triangle
- C++ Program to Print Right Triangle Star Pattern
- C++ Program to Print Left Triangle Star Pattern
- C++ Program to Print Upper Star Triangle Pattern
- C++ Program to Print Upward Triangle Star Pattern
- C++ Program to Print Downward Star Triangle Pattern
- C++ Program to Print Mirror Upper Star Triangle Pattern
- C++ Program to Print Hollow Right Triangle Star Pattern
- Swift program to Print Reverse Pyramid Star Pattern
- Swift Program to Print Reverse Numeric Pyramid Pattern
- Golang Program to Print Reverse Pyramid Star Pattern
- Swift Program to Print Reverse Pyramid Alphabetic Pattern

Advertisements