# Write a program to print Floyd’s triangle

18 July 2022

Write a program to print Floyd’s triangle

If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023

# Description

Get the number of rows as input and print the following pattern

Input

4

Output

1

2 3

4 5 6

7 8 9 10 11

C Program

#include <stdio.h>

int main()  {

int i, j, n, Num =1;

printf("Enter the number of rows: ");

scanf("%d", &n);

for(i=1; i<=n; i++)

{

for(j=1; j<=i; j++)

printf("%d ",  Num++ );

printf("\n");

}

return 0;

}

C++ Program

#include <iostream>

using namespace std;

int main()  {

int i, j, n, Num =1;

cout<<"Enter the number of rows: ";

cin>>n;

for(i=1; i<=n; i++)

{

for(j=1; j<=i; j++)

cout<<Num++ <<" ";

cout<<"\n";

}

return 0;

}

Java Program

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

int i,j,n,num=1;

System.out.print("Enter number of rows: ");

Scanner sc=new Scanner(System.in);

n=sc.nextInt();

for(i=1;i<=n;i++)

{

for(j=1;j<=i;j++)

{

System.out.print(num+" ");

num++;

}

System.out.println();

}

}

}

Python Program

row=int(input("Enter the number of rows: "))

num=1

for i in range(1,row+1):

for j in range(1,i+1):

print(num,end=" ")

num=num+1

print()

If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023