Example
Input :
Input rows : 5
Output :
* ** *** **** ***** **** *** ** *
Required Knowledge
Basic C++ programming, for loop, nested loop, if-else
Program to print half diamond star pattern
/**
C++ program to print half diamond star pattern series.
*/
#include <iostream>
using namespace std;
int main()
{
int i, j, N, columns;
/* Input number of columns from user */
cout<<"Enter number of columns:";
cin>>N;
columns=1;
for(i=1;i<N*2;i++)
{
for(j=1; j<=columns; j++)
{
cout<<"*";
}
if(i < N)
{
/* Increment number of columns per row for upper part */
columns++;
}
else
{
/* Decrement number of columns per row for lower part */
columns--;
}
/* Move to next line */
cout<<"\n";
}
return 0;
}