Pattern invertedHourGlass

my code has passed all the test cases but for custom input n>=11 it is not following the regular pattern… why???

#include
using namespace std;
int main() {
int n;
cin>>n;
for(int i=0;i<=n;i++){
int a=n;
for(int j=1;j<=i+1;j++){
cout<<a<<’ β€˜;
a–;
}
for(int k=1;k<=n-i;k++){
cout<<’ β€˜<<’ β€˜;
}
for(int k=1;k<n-i;k++){
cout<<’ β€˜<<’ β€˜;
}
a=n-i;
if(i==n){
for(int j=1;j<=n;j++){
cout<<j<<’ β€˜;
}
}
else{
for(int j=1;j<=i+1;j++){
cout<<a<<’ ';
a++;
}
}

	cout<<endl;
}

for(int i=1;i<=n;i++){
	int a=n;
	for(int j=1;j<=n-i+1;j++){
		cout<<a<<' ';
		a--;
	}
	for(int k=1;k<=i;k++){
		cout<<' '<<' ';
	}
	if(i!=1){
	for(int k=1;k<i;k++){
		cout<<' '<<' ';
	}
	}
	
	a=i;
		for(int j=1;j<=n-i+1;j++){
		    cout<<a<<' ';
		    a++;
		}

	cout<<endl;
}
return 0;

}

hey @rabimajumder08 this is happening because values>10 contain 2 digits whereas all other values which are < 10 have single digits, so all numbers after value 10 disturb the whole pattern so the solution is valid for values till 10 only.

hope it helped !! :slight_smile:

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.