MASTER PATTERNS

PROGRAMS

#include<iostream>
using namespace std;
int square();
int rectangle();
int triangle();
int diamond();
char choice();
int main()
{
int a;
cout<<"Enter your choice\n1 for Square\n2 for Rectangle\n3 for triangle\n4 for diamond";
cin>>a;
if(a==1)
square();
else if(a==2)
rectangle();
else if(a==3)
triangle();
else if(a==4)
diamond();
}
int square()
{
int size;
    cout << "\n\n Print a pattern like square with # character:\n";
    cout << "--------------------------------------------------\n";
    cout << " Input the number of characters for a side: ";
    cin >> size;
    for (int row = 1; row <= size; ++row) 
    {
        for (int col = 1; col <= size; ++col) 
        {
            cout << "* ";
        }
        cout << endl;
    }
    choice();
    return 0;
}
int rectangle()
{
cout<<"RECTANGLE"<<endl;
int row, width, spaces;
cout <<"Enter the number of rows: ";
cin >> row;
cout <<"Enter the rectangle width: ";
cin >> width;

        for(int i=0; i<row; i++)
        {
            for(int j=0; j<width; j++)
                cout << "*";
            cout << endl;
        }
        choice();
return 0;
}
int triangle()
{
cout<<"TRIANGLE"<<endl;
    int i, j, k,g;
    cout<<"Enter a no of rows:";
    cin>>g;
    for(i=1;i<=g;i++)
    {
        for(j=i;j<g;j++)
        {
         cout << " ";
        }
        for(k=1;k<(i*2);k++)
        {
            cout << "*";
        }
        cout <<endl;
    }
    choice();
    return 0;
}
int diamond(){

int i, j,o;
cout<<"DIAMOND"<<endl;
cout<<"ENTER A NO OF ROWS:";
cin>>o;
    for(i=1; i<=o; i++)
    {
        for(j=i; j<o; j++)
        {
            cout<<" ";
        }
        for(j=1; j<=(2*i-1); j++)
        {
            cout<<"*";
        }
        cout<<endl;
    }
    for(i=o; i>=1; i--)
    {
        for(j=i; j<=o; j++)
        {
            cout<<" ";
        }
        for(j=2; j<(2*i-1); j++)
        {
            cout<<"*";
        }
        cout<<endl;
    }
    choice();
    return 0;
}
char choice()
{
char z;
cout<<"Do you want to continue:";
    cin>>z;
    if(z=='y'||z=='Y')
    main();
    else
    cout<<"thanks";
return 0;
}

OUTPUT


Comments

Popular posts from this blog

Stack

EXTRA INFORMATION ABOUT TECHNOLOGY