Codeforcoding

Cpp program to Floyd’s triangle star pattern

Cpp program to Floyd’s triangle star pattern

In this tutorial, we will discuss Cpp program to Floyd’s triangle star pattern

We will learn how to create Floyd’s triangle star pattern in C++ language using nested for loop.

 

Pattern 1

Cpp program to floyd's triangle pattern
Floyd’s triangle pattern 1

Program 1

Floyd’s triangle Star pattern 1

C++ program to display the right triangle star pattern

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

int main()
{
    int i,j,rows;
    cout << "Enter value to number of rows" << endl;
    cin>>rows;//get input from user for rows
    for(i=1; i<=rows; i++){ //for display rows
        for(j=1; j<=i; j++){
        cout<<"*";//print star
    }
    cout<<"\n";//move to next line
    }
    getch();
    return 0;
}

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

Enter value to number of rows
9
*
**
***
****
*****
******
*******
********
*********

 

Pattern 2

Floyd’s triangle pattern 2

Program 2

Floyd’s triangle Star pattern 2

C++ program to display the mirrored right triangle star pattern

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

int main()
{
    int i,j,rows;
    cout << "Enter value to number of rows" << endl;
    cin>>rows;//get input from user for rows
    for(i=1; i<=rows; i++){ //for display rows
        for(j=i; j<=rows; j++){
        cout<<" ";//print star
    }
    for(j=1; j<=i; j++){
        cout<<"*";//print star
    }
    cout<<"\n";//move to next line
    }
    getch();
    return 0;
}

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

Enter the value to number of rows
9
                *
              **
            ***
          ****
        *****
      ******
    *******
  ********
*********

 

Pattern 3

Floyd’s triangle pattern 3

Program 3

Floyd’s triangle Star pattern 3

C++ program to display the reversed right triangle star pattern

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

int main()
{
    int i,j,rows;
    cout << "Enter the value for number of rows" << endl;
    cin>>rows;//get input from user for rows
    for(i=1; i<=rows; i++){ //for display rows
        for(j=i; j<=rows; j++){
        cout<<"*";//print star
    }
    cout<<"\n";//move to next line
    }
    getch();
    return 0;
}

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

Enter the value for number of rows
9
*********
********
*******
******
*****
****
***
**
*

Pattern 4

Floyd’s triangle pattern 4

Program 4

Floyd’s triangle Star pattern 4

C++ program to display the reversed mirrored right triangle star pattern

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

int main()
{
    int i,j,rows;
    cout << "Enter value for number of rows" << endl;
    cin>>rows;//get input from user for rows
    for(i=1; i<=rows; i++){ //for display rows
        for(j=1; j<=i; j++){
        cout<<" ";//print star
    }
    for(j=i; j<=rows; j++){
        cout<<"*";//print star
    }
    cout<<"\n";//move to next line
    }
    getch();
    return 0;
}

 

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

Enter value for number of rows
9
*********
  ********
    *******
      ******
        *****
          ****
            ***
              **
                *

 

Similar post

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

Pyramid star pattern in Cpp

Pyramid star pattern in C

Pyramid star pattern in Java 

 

Suggested for you

Loops in Java language

Loops in C language

Loops in C++ language

 

For loop in C++ language

For loop in Java 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

 

Nested for loop in Java language

Nested for loop in C++ language

Nested for loop in C language

Nested for loop in Python language

 

 

Cpp program to hollow triangle star pattern
Java code to triangle number pattern
Exit mobile version