Printing Pattern Using Loops

Sort by

recency

|

1064 Discussions

|

  • + 0 comments
    int main() 
    {
        int n;
        int absRow, absColumn;
        scanf("%d", &n);
        
        for(int row = n; row >= -n; row--)
        {
            if(row == 0 || row == -1)
            {
                continue;
            }
            for(int column = n; column >= -n; column--)
            {
                if(column == 0 || column == -1)
                {
                    continue;
                }
                absRow = abs(row);
                absColumn = abs(column);
                if(absColumn <= absRow)
                {
                    printf("%d ", absRow);
                }
                else
                {
                    printf("%d ", absColumn);
                }
            }
            printf("\n");
        }
       
        return 0;
    }
    
  • + 0 comments

    input n is difficult

  • + 0 comments

    my background is not CS! so I was stuck, bruteforcing this problem for a week until I asked the right questions and this popped up! https://www.geeksforgeeks.org/machine-learning/chebyshev-distance/

  • + 0 comments

    It’s a great exercise for understanding loop control, indexing, and pattern logic in programming! Play Exchange Login ID and Password

  • + 0 comments

    Printing Pattern Using Loops