Reverse Floyd’s triangle using for loop
C++
// C program to Demonstrate Reverse Floyd's // Triangle Using for loop #include <iostream> using namespace std; void reverse_floyd( int n) { // total number of elements int i = n * (n + 1) / 2; // condition for printing them while (i > 0) { for ( int j = 0; j < n; j++) printf ( "%d " , i--); n--; printf ( "\n" ); } } int main() { reverse_floyd(6); return 0; } |
Output:
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Time Complexity: O(n2)
Auxiliary Space: O(1)
C Program to Print Floyd’s Triangle Pyramid Patterns
Here we will build a C program to print Floyd’s Triangle Pyramid pattern. Floyd’s Triangle is a triangular array of natural numbers where the nth row contains n elements. There are 8 methods to cover all variations of Floyd’s Triangles
- Floyd’s triangle using for loop.
- Floyd’s triangle using while loop.
- Floyd’s triangle using recursion.
- Reverse Floyd’s triangle using for loop.
- Star Floyd’s triangle using for loop.
- Alphabets Floyd’s triangle using for loop.
Floyd’s Triangle of natural numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Floyd’s triangle of alphabets
a b c d e f g h i j
Star Floyd pattern
* * * * * * * * * *
Contact Us