Getting some extra rows in my pattern. Please help me with the correct logic in the code below:
Manmohan Loves Pattern 2
Hi priyansh
correct code:
#include
using namespace std;
int main() {
int n,a=1,i,j,k,zer=0;
cin>>n;
for(i=1;i<=n;i++){
if(i<=2){
for(k=1;k<=i;k++){
cout<<a<<" “;
}
cout<<endl;
}
else if(i>2 && i<=n){
cout<<i-1<<” “;
for(k=1;k<i-1;k++){
cout<<zer<<” “;
}
cout<<i-1<<” ";
cout<<endl;
}
}
return 0;
}
Hope it helps:)