Printing Pattern Using Loops

  • + 0 comments

    int main() {

    int n;
    scanf("%d", &n);
    int a[10000],m=((2*n)-1);
    int p=0,q=m,r=n; 
    // Complete the code to print the pattern.
    for(int o=0;o<r;o++){
    for(int i=p;i<q;i++){
        a[i]=n;
        }  
     for(int j=0;j<m;j++){
        printf("%d ",a[j]);
         }    
     p++;
     q--;
     n--;
     printf("\n");
    }
    n=n+2;
    for(int o=0;o<r-1;o++){
     p--;
     q++;
     for(int i=p;i<q;i++){
        a[i]=n;
        }  
     for(int j=0;j<m;j++){
        printf("%d ",a[j]);
         }    
    
     n++;
     printf("\n");
    }
    
    
    return 0;
    

    }