Tuesday, September 4, 2018

Printing Star pattern -2 Program

// 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;
for(int r=1; r<=num; r++) {
for(int c=1; c<=num-r+1; c++) // Inner Loop
// will run from 1 to num - r+1
//(value from outer loop)
// so with every line star will reduce
{
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