This is the pattern to be printed:
This is the code that I have written:
int n;
cin>>n;
int row,col;
int st=n-1; //no. of stars
int sp=1; //no. of spaces
int N=2*n-1;
for(row=1; row<=N; row++){
for(col=1; col<=st; col++){
cout<<"*"<<"\t";
}
for(col=1; col<=sp; col++){
cout<<"\t";
}
for(col=1; col<=st; col++){
cout<<"*"<<"\t";
}
if(row<=N/2){
st--;
sp=sp+2;
}
else{
st++;
sp=sp-2;
}
if((row=1) && (row=N)){
for(col=1; col<=N; col++){
cout<<"*"<<"\t";
}
}
cout<<endl;
}
The output shows “time limit exceeded”. What is the mistake?