Tuesday, 26 January 2016

Cpp program to print diamond with stars

This is a  Cpp Program which prints out the diamond with stars pattern.

Diamond with stars ( pattern)
Download Code
PROGRAM :

#include <iostream>

using namespace std;

int main()
{
    int i, j, k,n;
    cout << "Enter number of lines[height of diamond] : \t" ;
    cin >> n;
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
        {
            cout << " ";
        }
        for(k=1; k<(i*2); k++)
        {
            cout << "*";
        }
        cout << "\n";
    }
    for(i=n-1; i>=1; i--)
    {
        for(j=n; j>i; j--)
        {
            cout << " ";
        }
        for(k=1; k<(i*2); k++)
        {
            cout << "*";
        }
        cout << "\n";
    }

    return 0;
}


OUTPUT :
Cpp Program  - Diamond pattern with stars

Download Code