TOPIC

Can't understand what is wrong..please help me

Deen Ahmed asked 1 year ago

include include

using namespace std;

int main() {

int n,i,j; do { cin>>n; int a[n][n]; for(i=0;i<=n-1;i++) { for(j=0;j<=n-1;j++) { if(i>=j&&i+j<=n-1) { a[i][j]=j+1; } if(j>=i&&i+j<=n-1) { a[i][j]=i+1; } if(j>=i&&i+j>=n-1) { a[i][j]=n-1-j+1; } if(i>=j&&i+j>=n-1) { a[i][j]=n-i; }

}

} for(i=0;i<=n-1;i++) { for(j=0;j<=n-1;j++)

     if(j==0)
    {
        cout<<setw(3)<<a[i][j];
    }
    else
    {
        cout<<" "<<setw(3)<<a[i][j];
    }
cout<<endl;

}cout<<endl;

}while(n!=0);

return 0;

}

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.