Code: Star Pattern

 Code: Star Pattern

Send Feedback

Pattern for N = 4


The dots represent spaces.



Input Format :
N (Total no. of rows)
Output Format :
Pattern in N lines
Constraints :
0 <= N <= 50
Sample Input 1 :
3
Sample Output 1 :
   *
  *** 
 *****
Sample Input 2 :
4
Sample Output 2 :
    *
   *** 
  *****
 *******


#include<iostream>
using namespace std;


int main(){
int n;
cin>>n;
int row=1;
while(n>=row){
int col=1;
while(n-row>=col){
cout<<" ";
col++;
}
int digit=1;
while(row>=digit){
cout<<"*";
digit++;
}
int dec=row-1;
while(dec>=1){
cout<<"*";
dec--;
}
cout<<endl;
row++;
}
/* Read input as specified in the question.
* Print output as specified in the question.
*/
}



Comments

Popular posts from this blog

Code : All connected components

Coding Ninjas