Floyd's triangle | Practice | GeeksforGeeks

Given a number N. The task is to print Floyd's triangle with N lines.
Example 1:
Input:
N = 4

Output:
1
2 3
4 5 6
7 8 9 10

Explanation:
For N = 4 there are 4 rows in the output
and the number of elements increases 
with an increase in the row.
 
Example 1:
Input:
N = 5

Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Explanation:
For N = 5 there are 5 rows in the output
and the number of elements increases 
with an increase in the row.
Your Task:  
You don't need to read input. Your task is to complete the function printFloydTriangle() which takes an integer N as input parameter and prints the triangle.

Expected Time Complexity: O(N^2)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 100
0
anzellina201771 month ago
What is C program for the following output result ?
0
01
012
0123
01234
0
anzellina201771 month ago
        0
      01
    012
  0123
01234
What will be the source code of the above result?
0
vishwajeetofficial20222 months ago
//JAVA SOLUTION

class Solution{
    static void printFloydTriangle(int N){
        // code here
          int value = 1;
       for(int row=1;row<=N;row++){
           for(int column=1; column <= row;column++){
               System.out.print(value++ +" ");
           }
           System.out.println();
      }
   }
}
 
0
an10kitsingh4 months ago
def printFloydTriangle(self, N):       num = 1    for i in range(0, N+1):        for j in range(0, i):            print(num, end = ' ')            num+=1        print('')
 
What is wrong in this snippet, it keep failing for input 15?
0
pankajkumarravi6 months ago
 ========== Here Java Code==========
static void printFloydTriangle(int N){       // code here               int value = 1;       for(int row=1;row<=N;row++){           for(int column=1; column <= row;column++){               System.out.print(value++ +" ");           }           System.out.println();       }   }
0
rajmuskan0907 months ago
void printFloydTriangle(int n)
    {
        // Write Your Code here
        int number=1;
        for(int i=0;i<n;i++){
            for(int j=0;j<=i;j++){
                cout<<number<<" ";
                number++;
            }cout<<endl;
        }
    }
0
Please8 months ago
Please
ha ha https://media0.giphy.com/me...
0
Raushan Kumar10 months ago
Raushan Kumar
class Solution{    static void printFloydTriangle(int N){        // code here        int k=1;        for(int i=1;i<=N;i++)        {            for(int j=1;j<=i;j++)                {                    System.out.print(k+" ");                    k++;                }                System.out.println();        }    }}
0
sudhanshu gupta1 year ago
sudhanshu gupta
class Solution{public:    void printFloydTriangle(int N)    {        int a=1;        for(int i=1;i<=N;i++)        {            for(int j=1;j<=i;j++)            {                printf("%d ",a);                a++;            }            printf("\n");        }        }};
0
Sukanya Sinha1 year ago
Sukanya Sinha
class Solution{    static void printFloydTriangle(int N){      int k =1;      for(int i=1;i<=N;i++){          for(int j=1;j<=i;j++){              System.out.print(k+" ");              k++;          }          System.out.println();      }    }}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.