Pattern mountain

I don’t know why it is giving all testcases wrong but on running I am getting wrong output

#include
using namespace std;
int main() {
int i,b,z=1,row=1,a=1,c=1,space;
cin>>i;
space=(2*i)-3;
while(z<=i){
while(a<=row){
cout<<a;
a=a+1;
}
a=a-1;
if(c<=space){
while(c<=space){
cout<<" ";
c=c+1;
}
}
if(z==i)
a=a-1;

    while(a>=1){
    cout<<(a);
    a=a-1;
    }
            
    a=1;
    c=1;
    space=space-2;
    row=row+1;
    z=z+1;
    cout<<endl;
}
return 0;

}

Hello @Saksham12,

if you would observe the sample output given in the question, then you would realize that each element in the pattern is separated by a tab

I have modified your code:

Hope, this would help.
Give a like if you are satisfied.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.