// C++ Programming Code To Create Pyramid Star Pattern using Single For Loop
#include<bits/stdc++.h>
using namespace std ;
int main()
{
int rows, columns ;
int count=0 ;
cout<<"Enter height of the stars pyramid : " ;
cin>>rows ;
// number of columns in the required pyramid
columns=(2*rows)-1 ;
for(int i=1; i<=columns; i++)
{
if(i<rows-count)
cout<<" " ; //print spaces upto (total_no_of_rows-i) places in each row
else
cout<<"*" ;
if(i==rows+count)
{
cout<<"\n" ; // new line after printing each pattern in a row
count++ ;
if(i==columns)
break ;
i=0 ; // starts rows from 1st column
}
}
}

No comments:
Post a Comment