Why this is showing wrong testcases code is working well although

#include
using namespace std;

int main() {
int i,j,k,n,l,m,z;
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
cout<<j;
}for(k=1;k<=((n2)-1-(2i));k++)
{cout<<" ";}
if(i!=n)
{
for(z=i;z>0;zā€“)
{

		cout<<z;}}
		if(i==n)
		{for(l=n-1;l>0;l--)
		cout<<l;


		}

cout<<endl;

	}





}

The logic that you used is perfectly fine. It is showing wrong output because you have not taken in account the number of spaces between consecutive numbers.
For eg : the actual output for 3rd line is 1 2 3 3 2 1 , but your code will print 123 321.
Just add the spaces between consecutive numbers and your code will work for sure.
Hope that helps.