Thursday, September 6, 2018

star pattern - part 3 video

#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 sp=1;sp<=num-r;sp++)//spaces before star
// num 5- r 1 = 5 1 to 4
  cout<<" ";
for(int c=1 ; c<=r; 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