Floyd’s triangle using for loop
C
// C program to Demonstrate Floyd's Triangle // Using for loop #include <stdio.h> void floyd( int n) { int i, j = 1; // Condition printing the number of element for (i = 1; i <= (n * (n + 1)) / 2; i++) { printf ( "%d " , i); // condition for row of number of element printing if (i == (j * (j + 1)) / 2) { printf ( "\n" ); j++; } } } 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