Program to Print Floyd's Triangle Last Updated : 16 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice Floyd's triangle is a triangle with first natural numbers. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Recommended PracticeFloyd\'s triangleTry It! Following program prints Floyd's triangle with n lines. C++ #include <bits/stdc++.h> using namespace std; void printFloydTriangle(int n) { int i, j, val = 1; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) cout << val++ << " "; cout << endl; } } // Driver Code int main() { printFloydTriangle(6); return 0; } // This is code is contributed // by rathbhupendra C // Without using a temporary variable and with only one loop #include<stdio.h> void floyd(n){ int i,j=1; for (i=1;i<=(n*(n+1))/2;i++){ printf("%d ",i); if(i==(j*(j+1))/2){ printf("\n"); j++; } } } int main(){ floyd(6); } //This code is contributed by Vishal B Java // Java program to print // Floyd's triangle class GFG { static void printFloydTriangle(int n) { int i, j, val = 1; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { System.out.print(val + " "); val++; } System.out.println(); } } // Driver Code public static void main(String[] args) { printFloydTriangle(6); } } Python3 # Python3 program to print # Floyd's triangle def floydTriangle(n): val = 1 for i in range(1, n + 1): for j in range(1, i + 1): print(val, end = " ") val += 1 print("") floydTriangle(6) # This code is contributed by # Smitha Dinesh Semwal C# // C# program to print // Floyd's triangle using System; class GFG { static void printFloydTriangle(int n) { int i, j, val = 1; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { Console.Write(val + " "); val++; } Console.WriteLine(); } } // Driver Code public static void Main() { printFloydTriangle(6); } } PHP <?php // PHP code to print Floyd's Triangle // Function to display Floyd's Triangle function FloydsTriangle($n) { $val = 1; // loop for number of lines for($i = 1; $i <= $n; $i++) { // loop for number of elements // in each line for($j = 1; $j <= $i; $j++) { print($val." "); $val++; } print("\n"); } } // Driver's Code $n = 6; FloydsTriangle($n); // This code is contributed by akash7981 ?> JavaScript <script> // Javascript implementation function printFloydTriangle(n) { var i, j, val = 1; for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) document.write(val++ + " "); document.write("<br>"); } } // Driver Code printFloydTriangle(6); // This is code is contributed // by shivani </script> 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), since no extra space has been taken. Comment More infoAdvertise with us Next Article Program to Print Floyd's Triangle K kartik Follow Improve Article Tags : Mathematical C Language DSA Basic Coding Problems pattern-printing +1 More Practice Tags : Mathematicalpattern-printing Similar Reads Program to print Reverse Floyd's triangle Floydâs triangle is a triangle with first natural numbers. Task is to print reverse of Floydâs triangle.Examples: Input : 4 Output : 10 9 8 7 6 5 4 3 2 1 Input : 5 Output : 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 C++ // CPP program to print reverse of // floyd's triangle #include <bits/stdc++.h> u 3 min read Program to print binary right angle triangle Binary right angle triangle consists of only 0's and 1's in alternate positions. Examples : Input : 4 Output : 0 1 0 0 1 0 1 0 1 0 Input : 3 Output : 0 1 0 0 1 0 C++ // C program to print binary right angle // triangle. #include <stdio.h> // function to print binary right angle // triangle voi 4 min read Program to print Sum Triangle for a given array Given a array, write a program to construct a triangle where last row contains elements of given array, every element of second last row contains sum of below two elements and so on. Example: Input: arr[] = {4, 7, 3, 6, 7};Output:8140 4121 19 2211 10 9 134 7 3 6 7 Input: {10, 40, 50}Output:14050 901 9 min read Floyd's triangle in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Floyd's triangle is a right-angled triangular array of 2 min read Program to print a Hollow Triangle inside a Triangle Given a number N(? 8), the task is to print a Hollow Triangle inside a Triangle pattern.Example: Input: N = 9 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Approach: Let i be the index for rows and j be the index for columns. Then: For sides of outer triangle: If th 7 min read Like