pls correct my code my code fail in sevral testcases and also correct my code
#include
using namespace std;
int main() {
int n;
cin>>n;
int k = n/2+1;
for(int i = 1;i <= k;i++){
for(int space = 3k-4(i-1);space>0;space–){
cout<<" “;
}
for(int j = i;j>0;j–){
cout<<j<<” “;
}
if(i>1){
for(int space = 1;space<3+4*(i-2);space++){
cout<<” ";
}
for(int j = 1;j<=i;j++){
cout<<j<<" ";
}
}
cout<<endl;
}
for(int i = 1;i <=k;i++){
for(int s = 1;s<=k+4*(i-1);s++){
cout<<" ";
}
for(int j = k-i;j >0;j--){
cout<<j<<" ";
}
if(i < 3){
for(int s = 1;s<=n - 4*(i-1) - 1;s++){
cout<<" ";
}
for(int j = 1;j <= k-i;j++){
cout<<j<<" ";
}
}
cout<<endl;
}
return 0;
}