Printing Pattern Using Loops

  • + 0 comments

    include

    include

    include

    include

    int main() { int n; scanf("%d",&n);

    int size = (n*2)-1;
    int hub =size;
    

    for (int row=1 ;row <=n;row++ ){ hub--; for (int col=1;col<=size;col++){

        printf("%d ",n);
    
        if (row>col && row>1 ){
            if (row>=col){n--;}
    
        }   
        else if (col>hub  &&row >1&& size !=col  ){n++;}
    

    }

        printf("\n")  ;  
     }
     int a =n;
     int hub_add=n+1;
     int hub_sub=n-2;
     for (int row=1;row <n;row++){
    
         a=n;
         for (int col=1;col<=size;col++){
         printf("%d ",a);
         if(row!=n-1){
         if (hub_sub>=col  ){
             a--;
         }
          if (hub_add<=col ){
             a++;
    
         }
         }
         }
            hub_add++;
            hub_sub--;
                  printf("\n");
    
     }
    

    }