Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

diamond star pattern in cpp

include <bits/stdc++.h>             //       *
using namespace std;                //      ***
int main()                          //     *****
{                                   //      ***
    int n, i, j;                    //       *
	cin>>n;
    int m = n;
 // FOR UPPER Half
	for(i=1; i<=n; i++)
	{
		for(j=0; j<m-1; j++)
			cout<<" ";

		for(j=0; j<2*i-1; j++)
			cout<<"*";

		cout<<"
";
		m--;
	}
  // FOR LOWER Half
	for(i=n-1; i>=1; i--)
	{
		for(j=0; j<m+1; j++)
			cout<<" ";
		for(j=0; j<2*i-1; j++)
			cout<<"*";
		    cout<<"
";
		m++;
	}
}
 
PREVIOUS NEXT
Tagged: #diamond #star #pattern #cpp
ADD COMMENT
Topic
Name
9+6 =