Printing Pattern Using Loops

  • + 0 comments

    Most solution I see starts for loops from 0 or 1. Go out of the box and start the for loop from negative. It's easier to understand.

    int main() 
    {
    
        int n;
        scanf("%d", &n);
        for (int i = -(n-1); i < n; i++){
            for (int j = -(n-1); j < n; j++){
                    printf("%d ", abs(j)+1 > abs(i)+1 ? abs(j)+1 : abs(i)+1);
            }
            printf ("\n");
        }
        return 0;
    }