C++ Program to Print Plus Star Pattern

Write a C++ program to print plus star pattern using for loop. 

#include<iostream>
using namespace std;

int main()
{
	int i, j, k, rows;
     
    cout << "Enter Plus Star Pattern Row = ";
    cin >> rows;

    cout << "Plus Star Pattern\n"; 

    for(i = 1; i <= rows * 2 - 1; i++)
    {
        if(i != rows)
        {
            for(j = 1; j <= rows; j++)
            {
                if(j == rows)
                {
                    cout << "*";
                }
                cout << " ";
            }
        }
        else
        {
            for(k = 1; k <= rows * 2 - 1; k++)
            {
                cout << "*";
            }
        }
        cout << "\n";
    }	
 	return 0;
}
C++ Program to Print Plus Star Pattern

This C++ example prints the plus pattern of a given character using a while loop.

#include<iostream>
using namespace std;

int main()
{
	int i = 1, j, k, rows;
    char ch;
     
    cout << "Enter Plus Star Pattern Row = ";
    cin >> rows;

    cout << "Enter Symbol for Plus Star Pattern = ";
    cin >> ch;

    cout << "Plus Star Pattern\n"; 
 
    while(i <= rows * 2 - 1)
    {
        if(i != rows)
        {
            j = 1;
            while( j <= rows)
            {
                if(j == rows)
                {
                    cout << ch;
                }
                cout << " ";
                j++;
            }
        }
        else
        {
            k = 1;
            while( k <= rows * 2 - 1)
            {
                cout << ch;
                k++;
            }
        }
        cout << "\n";
        i++;
    }	
 	return 0;
}
Enter Plus Star Pattern Row = 9
Enter Symbol for Plus Star Pattern = &
Plus Star Pattern
        & 
        & 
        & 
        & 
        & 
        & 
        & 
        & 
&&&&&&&&&&&&&&&&&
        & 
        & 
        & 
        & 
        & 
        & 
        & 
        & 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.