Floyd's triangle

triangle number pattern Using nested while in Cpp

triangle number pattern Using nested while in Cpp

In this tutorial, we will learn about the triangle Number pattern using nested while in Cpp language.

We can use nested while loop in C++ to write coding for Squares, rectangles, Floyed triangle, Pyramid triangles and many other shapes.

In this tutorial, we will learn about some of the Floyd’s triangle shapes and how to write coding for that in C++ programming language.

Program to print triangle pattern using the number

Program 1

Floyd’s triangle number pattern 1

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int rows;
    cout << "Floyd's triangle pattern" << endl;
    cout << "Enter the number of rows: ";
    cin>>rows;
    int i=1;
    while(i<=rows){//outer while loop
            int j=1;
    while(j<=i){//inner while loop
            cout<<j;
    j++;
    }
    cout<<"\n";
    i++;
    }
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

Floyd's triangle pattern
Enter the number of rows: 6
1
12
123
1234
12345
123456

Program 2

Floyd’s triangle number pattern 2

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int rows;
    cout << "Floyd's triangle pattern" << endl;
    cout << "Enter the number of rows" << endl;
    cin>>rows;
    int i=1;
    while(i<=rows){//outer while loop
            int j=1;
    while(j<=i){//inner while loop
            cout<<i;
    j++;
    }
    cout<<"\n";
    i++;
    }
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

Floyd's triangle pattern
Enter the number of rows: 6
1
22
333
4444
55555
666666

Program 3

Floyd’s triangle number pattern 3

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int rows;
    cout << "Floyd's triangle pattern" << endl;
    cout << "Enter the number of rows: ";
    cin>>rows;
    int row=1;
    int i=1;
    while(i<=rows){//outer while loop
            int j=1;
    while(j<=i){//inner while loop
            cout<<row<<" ";
            row++;
    j++;
    }
    cout<<"\n";
    i++;
    }
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

Floyd's triangle pattern
Enter the number of rows: 6

1
2 3
4 5 6 
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21

Program 4

Floyd’s triangle number pattern 4

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    cout << "Floyd's triangle pattern" << endl;
    int i=1,j,k,row=8,num=0;
    while(i<=row){//outer while loop
            int k=1;
    while(k<=row-(row-i)){//inner while loop
            cout<<" ";
            k++;
    }
    num=row-i;
    j=1;
    while(j<=num){
        cout<<row-(row-j);
        j++;
    }
    i++;
    cout<<"\n";
    }
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

Floyd's triangle pattern
1234567
  123456
    12345
      1234
        123
          12
            1

 

Similar post

Java program to print star pyramid pattern 

C program to print star pyramid pattern 

C++ program to print star pyramid pattern 

Python program to print star pyramid pattern 

Floyd’s triangle number pattern using for loop in C

Floyd’s triangle pattern using nested for loop in Java

Floyd’s triangle pattern using nested while loop in Java

Hollow pyramid triangle pattern in C++ language

Rhombus pattern in Java using for loop

Rhombus pattern in C using while loop

Rhombus pattern in C++ using do-while loop

 

Suggested for you

For loop in Java language

For loop in C++ language

For loop in C language

For loop in Python language

 

While loop in Java language

While loop in C language

While loop in C++ language

While loop in Python language

 

Do-while loop in Java language

Do-while loop in C language

Do-while loop in C++ language

 

Nested for loop in Java language

Nested for loop in C++ language

Nested for loop in C language

Nested for loop in Python language

 

triangle number pattern using nested while in C
Java code to display patterns using do while loop
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.

View Comments

  • how do you make a triangle number pattern that outputs
    1
    2 6
    3 7 10
    4 8 11 13
    5 9 12 14 15

    number of rows depends on input

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

20 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago