Monday, September 10, 2018

Print pyramid of stars

/* Program to print Pattern - Triangle of stars
*
   * * *
* * * * *
*/
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int num; // To input number of lines
cout<<"Enter Number "; cin>>num;
int r,c;
for(r=1; r<=num; r++) {
for(int sp=1;sp<=num-r;sp++) cout<<"  ";
for(c=1 ; c<=2*r-1; c++)
{
cout<<"* "; // will print * in a single line
}
cout<<"\n"; // At end of inner loop next line will
// come in a new line
}
getch();
}

No comments:

Post a Comment