Floyd's triangle

Triangle Hollow Pattern using nested while loop in Cpp

Triangle Hollow Pattern using nested while loop in Cpp

In this tutorial, we will discuss Triangle Hollow Pattern using nested while loop in Cpp

In this program, we are going to learn about how to display  Hollow Tringle star pattern using nested while loop in C++ programming  language

Here, we display an Hollow triangle Pattern program with coding using nested while loop and also program get input from the user using Cin function in C++  programming language

The user can provide numbers as they wish and get the  Hollow Triangle pattern according to their input.

Floyd’s triangle star pattern 1

Program 1

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

int main()
{
    int rows;
    cout<<"Enter the number of rows" << endl;
    cin>>rows;
    int i,j;
    i=1;
    while(i<=rows){
        j=1;
        while(j<=i){
        

    if(j==1 || j==i ||i==rows )
        cout<<"*";
    else
        cout<<" ";
    j++;;
}
i++;
cout <<"\n";//Move to the next line for print
    }
    getch();
    return 0;
}

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

Floyd’s triangle star pattern 1

Floyd’s triangle star pattern 2

Program 2

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

int main()
{
    int rows;
    cout<<"Enter the number of rows" << endl;
    cin>>rows;
    int i,j;
    i=1;
    while(i<=rows){
        j=i;
        while(j<rows){
        cout<<" ";
        j++;
        }
        j=1;
        while(j<=i){

    if(j==i || j==1 ||i==rows )
        cout<<"*";
    else
        cout<<" ";
    j++;;
        }
        i++;
cout<<"\n";//Move to the next line for print
}

    getch();
    return 0;
}

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

Floyd’s triangle star pattern 2

 

Floyd’s triangle star pattern 3

Program 3

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

int main()
{
    int rows;
    cout<<"Enter the number of rows" << endl;
    cin>>rows;
    int i,j;
    i=1;
    while(i<=rows){
        j=1;
        while(j<=rows){

    if(j==i || j==rows ||i==1 )
        cout<<"*";
    else
        cout<<" ";
    j++;;
        }
        i++;
cout<<"\n";//Move to the next line for print
}


    getch();
    return 0;
}

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

Floyd’s triangle star pattern 3

Floyd’s triangle star pattern 4

Program 4

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

int main()
{
    int rows;
    cout<<"Enter the number of rows" << endl;
    cin>>rows;
    int i,j;
    i=1;
    while(i<=rows){
        j=i;
        while(j<=rows){

    if( i==1|| j==i || j==rows)
        cout<<"*";
    else
        cout<<" ";
    j++;;
        }
        i++;
cout<<"\n";//Move to the next line for print
}
getch();
return 0;
}

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

Floyd’s triangle star pattern 4

 

Suggested for you

Operator in C++ language

Data type in C++ language

While loop in C++ language

Nested while loop in C++ language

 

Create hollow diamond star pattern in C
Hollow Triangle star Pattern using while loop in Java
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…

1 month ago

PHP Full Pyramid pattern program

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

1 month 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