Printing Pattern Using Loops

  • + 0 comments
    
    
    scanf("%d", &n);
    // Complete the code to print the pattern.
    for(i=0;i<n;i++){
        temp=n;
        for(j=0;j<n;j++){
          printf("%d ",temp);
          if(j<i)
            temp--;
        }
        for(j=(n-2);j>0;j--){
          if(j<i)
            temp++;
            printf("%d ",temp);
        }
        printf("%d\n",n);
    }
    for(i=0;i<(n-1);i++){
        temp=n;
        for(j=n;j>0;j--){
          printf("%d ",temp);
          if((i+2)<j)
            temp--;
        }
        for(j=0;j<(n-2);j++){
          if(i<j)
            temp++;
          printf("%d ",temp);
        }
        printf("%d\n",n);
    }
    

    `