Program to print Floyd's Triangle

2 3

4 5 6

7 8 9 10

11 12 13 14 15


Problem Statement:- Program to display Floyd's Triangle Number Pattern.


Sample Input/Output:-


Sample Input First:4

Sample Output First: 

1        
2 3      
4 5 6    
7 8 9 10 

Sample Input Second: 5


Sample Output Second: 

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

Data requirement:-


  Input Data:- row_size


  Output Data:- print_counter


  Additional Data:- ins, out


Program in C

Here is the source code of the C Program to Print Floyd's Triangle Number pattern.


Code:

#include <stdio.h>
int main()
{
  int row_size;

  /*Taking Input of the Floyd's Triangle row size*/
  printf("Enter the Row Size:");
  scanf("%d", &row_size);

  int print_counter = 1outins;

  /*display the Floyd's Triangle*/
  for (out = 1out <= row_sizeout++)
  {
    for (ins = 1ins <= outins++)
    {
      printf("%d "print_counter);
      print_counter++;
    }
    printf("\n");
  }
  return 0;
}


Input/Output:

Enter the Row Size:3

2 3

4 5 6


Program in C++

Here is the source code of the C++ Program to Display Floyd's Triangle Number Pattern.


Code:

#include <iostream>
using namespace std;
int main()
{
    int row_size;

    /*Taking Input of the Floyd's Triangle row size*/
    cout << "Enter the Row Size:";
    cin >> row_size;

    int print_counter = 1outins;

    /*display the Floyd's Triangle*/
    for (out = 1out <= row_sizeout++)
    {
        for (ins = 1ins <= outins++)
        {
            cout << print_counter << " ";
            print_counter++;
        }
        cout << endl;
    }
    return 0;
}


Input/Output:

Enter the Row Size:4

1        

2 3      

4 5 6    

7 8 9 10


Program in Java

Here is the source code of the Java Program to Print Floyd's Triangle Number pattern.


Code:

import java.util.Scanner;

public class FloydsTriangle {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        /*Taking Input of the Floyd's Triangle row size */
        System.out.print("Enter the Row Size:");
        int row_size = sc.nextInt();

        int print_counter = 1outins;

        /* display the Floyd's Triangle */
        for (out = 1out <= row_sizeout++) {
            for (ins = 1ins <= outins++) {
                System.out.print(print_counter + " ");
                print_counter++;
            }
            System.out.println();
        }
    }
}


Input/Output:

Enter the Row Size:3

2 3

4 5 6 


Program in Python

Here is the source code of the Python Program to display Floyd's Triangle Number pattern.


Code:

# Taking Input of the Floyd's Triangle row size
row_size = int(input("Enter the Row Size:"))
print_counter = 1

# display the Floyd's Triangle
for out in range(row_size):
    for ins in range(out+1):
        print(print_counterend=" ")
        print_counter += 1
    print("\r")


Input/Output:

Enter the Row Size:3

2 3

4 5 6




Post a Comment

0 Comments