Help me find the error

/* we are supposed to print a pattern like such

                        4 4 4 4 4 4 4  
                        4 3 3 3 3 3 4   
                        4 3 2 2 2 3 4   
                        4 3 2 1 2 3 4   
                        4 3 2 2 2 3 4   
                        4 3 3 3 3 3 4   
                        4 4 4 4 4 4 4   

*/

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{
int n;
scanf("%d",&n);
int size=2*n-1;
int a[size][size];
int start=0;
int end=size-1;
while(n!=0)
{
for(int i=start;i<=end;)
{
for(int j=start;j<=end;j++)
{
if(i==start||j==start||i==end||j==end)
a[i][j]=n;
}
}
start++;
end–;
n–;
}
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
printf("%d",a[i][j]);
printf("\n");
}
return 0;
}

for(int i=start;i<=end;)

You’re not incrementing i any where for a start, leading to an infinite loop.

1 Like