C++

Floyd’s triangle star patterns in C++ language using for loop

Floyd’s triangle star patterns in C++ language

In this tutorial, we will discuss Floyd’s triangle patterns in C++ language

In this post, we will learn how to create Floyd,s triangle star pattern using for loop

In the C++ language, we can display many patterns (star, number, alphabet, binary patterns using for loop, while loop and do-while loop)

Here, we can print floyd;s triangle satr pattern using nested for loop in C++ language

Triangle star patterns

Triangle star pattern `1

Program 1

This program allows the user to enter the number of rows and then it displays the right triangle star pattern using for loop in c language

#include <iostream>
using namespace std;
int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows: ";
    cin>>rows;
    for(i=1;i<=rows;++i)
    {
        for(j=1;j<=i;++j)
        {
           cout<<"* ";
        }
        cout<<"n";
    }
    return 0;
}

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

Pattern 1

Triangle star pattern `2

This program allows the user to enter the number of rows and then it displays the inverted right triangle star pattern using for loop in c language

Program 2

#include <iostream>
using namespace std;
int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows: ";
    cin>>rows;
    for(i=rows;i>=1;--i)
    {
        for(j=1;j<=i;++j)
        {
           cout<<"* ";
        }
        cout<<"n";
    }
    return 0;
}

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

Pattern 2

Triangle star pattern `3

This program allows the user to enter the number of rows and then it displays the mirrored right triangle star pattern using for loop in c language

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

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

    for(k=rows; k>=i; k--){
        cout<<"*";
    }
     cout<<"\n";
    }
    getch();
    return 0;
}

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

Pattern 3

Triangle star pattern `4

This program allows the user to enter the number of rows and then it displays the inverted mirrored right triangle star pattern using for loop in c language

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

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

    for(k=1; k<=i; k++){
        cout<<"*";
    }
     cout<<"\n";
    }
    getch();
    return 0;
}

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

Pattern 4
Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.