Printing Pattern Using Loops

  • + 0 comments

    int main() {

    int a,b,i,j,k,p,n,m[1000];
    scanf("%d", &n);
    // Complete the code to print the pattern.
    k = (2*(n))-1;
    a = k;
    b = n;
    
    //printf("%d",(n/2)+1);
    for(i=1;i<=a;i++)
    {  
        if (i<=(a/2)+1)
        {
            for(j=i;j<=k;j++)
            {
            m[j] = n;    
            }
            for(p=1;p<=a;p++)
            {
            printf("%d ",m[p]);
            }
            printf("\n");
            n--;
            k--;   
         }
         else if (i>(a/2)+1)
         {
            n++;
            //k++;
            // printf("%d\n",n);
            // printf("%d\n",k);
            for(j=i;j>=k;j--)
            {
            m[j] = n+1;      
            }
            for(p=1;p<=a;p++)
            {
            printf("%d ",m[p]);
            }
            printf("\n");
            k--; 
         }
    
                Can anyone help me whats wrong with the code. Im getting segmentation fault when Im submitting it.
    
    }
    return 0;
    

    }