1 
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:-
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 = 1, out, ins;
  /*display the Floyd's Triangle*/  for (out = 1; out <= row_size; out++)  {    for (ins = 1; ins <= out; ins++)    {      printf("%d ", print_counter);      print_counter++;    }    printf("\n");  }  return 0;}
Input/Output:
Enter the Row Size:3
1 
2 3
4 5 6
#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 = 1, out, ins;
  /*display the Floyd's Triangle*/  for (out = 1; out <= row_size; out++)  {    for (ins = 1; ins <= out; ins++)    {      printf("%d ", print_counter);      print_counter++;    }    printf("\n");  }  return 0;}
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 = 1, out, ins;
    /*display the Floyd's Triangle*/    for (out = 1; out <= row_size; out++)    {        for (ins = 1; ins <= out; ins++)        {            cout << print_counter << " ";            print_counter++;        }        cout << endl;    }    return 0;}
#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 = 1, out, ins;
    /*display the Floyd's Triangle*/    for (out = 1; out <= row_size; out++)    {        for (ins = 1; ins <= out; ins++)        {            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 = 1, out, ins;
        /* display the Floyd's Triangle */        for (out = 1; out <= row_size; out++) {            for (ins = 1; ins <= out; ins++) {                System.out.print(print_counter + " ");                print_counter++;            }            System.out.println();        }    }}
Input/Output:
Enter the Row Size:3
1 
2 3
4 5 6 
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 = 1, out, ins;
        /* display the Floyd's Triangle */        for (out = 1; out <= row_size; out++) {            for (ins = 1; ins <= out; ins++) {                System.out.print(print_counter + " ");                print_counter++;            }            System.out.println();        }    }}
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 sizerow_size = int(input("Enter the Row Size:"))print_counter = 1
# display the Floyd's Trianglefor out in range(row_size):    for ins in range(out+1):        print(print_counter, end=" ")        print_counter += 1    print("\r")
Input/Output:
Enter the Row Size:3
1 
2 3
4 5 6
# Taking Input of the Floyd's Triangle row sizerow_size = int(input("Enter the Row Size:"))print_counter = 1
# display the Floyd's Trianglefor out in range(row_size):    for ins in range(out+1):        print(print_counter, end=" ")        print_counter += 1    print("\r")
 

0 Comments
Please do not Enter any spam link in the comment box