Floyd’s triangle using while loop
C
// C program to Demonstrate Floyd's Triangle // Using while loop #include <stdio.h> void floyd( int n) { int i = 1, j = 1; // condition for number of element while (i <= (n * (n + 1)) / 2) { printf ( "%d " , i); // condition for what element has to print and // how many times if (i == (j * (j + 1)) / 2) { printf ( "\n" ); j++; } i++; } } int main() { floyd(6); } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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