Floyd's triangle

CPP program to print Floyd’s triangle number patterns

CPP program to print Floyd’s triangle number patterns

In this tutorial, we will discuss about CPP program to print Floyd’s triangle number patterns

In C++ language, we can write different Floyd’s triangle number pattern program using nested for loop.

To understand this pattern, you must know how for loop and nested for loop works in C++  language

C++ floyd’s triangle number pattern  programs

Number pattern 1

number pattern 1
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,row;
    cout<<"Enter the value for row :";
    cin>>row;
    cout << "The number floyd's triangle patterns" << endl;
    for(i=1; i<=row; i++ ){
        for(j=1; j<=i; j++ ){
        cout<<i<<" ";

    }
    cout<< endl;

    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Enter the value for the row: 8
The number Floyd's triangle pattern
1
22
333
4444
55555
666666
7777777
88888888

Number pattern 2

 

floyd’s triangle pattern 2
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,row;
    cout<<"Enter the value for row :";
    cin>>row;
    cout << "The number floyd's triangle patterns" << endl;
    for(i=1; i<=row; i++ ){
        for(j=1; j<=i; j++ ){
        cout<<j<<" ";

    }
    cout<< endl;

    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Enter the value for the row: 7
The number Floyd's triangle pattern
1
12
123
1234
12345
123456
1234567

 

Number pattern 3

Floyd’s triangle number pattern 3
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,k=1,rows;
    cout<<"Enter number of rows";
    cin>>rows;
    cout<<"You entered 8 \n here your triangle pattern\n";
    for(i=1; i<=rows; i++){
        for(j=1; j<=i; j++){
        cout<<k<<" ";
        k++;
    }
    cout<< endl;
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Enter number of rows: 8
you entered 8
 here your triangle pattern
1
2  3
4  5  6
7  8  9  10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36

 

Number pattern 4

Floyd’s triangle number pattern 4

inverted floyd’s triangle pattern printing using nested for loop

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows you want :";
    cin>>rows;
    cout << "here your "<<rows << " number of rows floyd's triangle"<<endl;
    for(i=rows; i>=1; i--){
        for(j=1; j<=i; j++){
        cout<<j<<" ";
    }
    cout<<endl;
    }
    getch();
    return 0;
}

When the above code is executed, it produces the following results:

Enter number of rows you want: 8
here your 8 number of Floyd's triangle
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5 
1 2 3 4
1 2 3
1 2
1

 

Number pattern 5

floyd’s triangle pattern printing using for loop and while loop

floyd triangle pattern 5
#include <iostream>

using namespace std;

int main()
{
    int rows,n;
    cout<<"Enter the number of rows you want :";
    cin>>rows;
    cout << "Here number pattern is:" << endl;
    for(int i=1; i<=rows; ++i)
    {
        n=rows-i;
        while(n>0)
        {
            cout<<" ";
            n--;
        }
        for(int j=i; j>=1; j--)
        {
            cout<<j;
        }
        cout<<"\n";
    }
    return 0;
}

When the above code is executed, it produces the following results:

              1
            21
          321
        4321
      54321
    654321
  7654321
87654321

 

Suggested for you

For loop in C++ language

For loop in Java language

For loop in C language

For loop in Python language

 

Nested for loop in C++ language

Nested for loop in Java language

Nested for  loop in C language

Nested for loop in Python language

 

 

 

Inverted Pyramid number pattern in Java
Java code to reverse order triangle number patterns
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago