Pattern problem

Required output
00000
0XXX0
0X0X0
0XXX0
00000
#include
using namespace std;
int main() {
int r,c1;
cin>>r>>c1;
int startRow=0,endRow=r-1,startColumn=0,endColumn=c1-1;
char c[r][c1];
bool f=false;
while(startRow<=endRow && startColumn<=endColumn){
if(f==false){
for(int i=startColumn;i<=endColumn;i++)
{
c[startRow][i]=‘0’;
}startRow++;
for(int i=startRow;i<=endRow;i++)
{
c[i][endColumn]=‘0’;
}endColumn–;
if(startRow<endRow)
{
for(int i=endColumn;i>=startColumn;i–)
{
c[endRow][i]=‘0’;
}
}endRow–;
if(startRow<endRow)
{
for(int i=endRow;i>=startRow;i–)
{
c[i][startColumn]=‘0’;
}

    }startColumn++;
    f=true;
}
if(f==true)
{
    for(int i=startColumn;i<=endColumn;i++)
    {
        c[startRow][i]='x';
    }startRow++;
    for(int i=startRow;i<=endRow;i++)
    {
        c[i][endColumn]='x';
    }endColumn--;
    if(startRow<endRow)
    {
        for(int i=endColumn;i>=startColumn;i--)
        {
            c[endRow][i]='x';
        }
    }endRow--;
    if(startRow<endRow)
    {
        for(int i=endRow;i>=startRow;i--)
        {
            c[i][startColumn]='x';
        }

    }startColumn++;
    f=false;
}

}
for(int i=0;i<r;i++)
{

for(int j=0;j<c1;j++){
    cout<<c[i][j];
}cout<<endl;

}
}

i am not getting the required output always one X goes missing

Hi @Subhasish_Mishra
Can you please share this question’s hacker block problem id so that i can see the problem statement. If it is not a hacker block problem so please share the link to this problem.

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.