Printing Pattern Using Loops

  • + 0 comments

    include

    include

    include

    include

    int main() {

    int n;
    scanf("%d", &n);
    // Complete the code to print the pattern.
    int L = 2 * n - 1;
    
    for (int i = 1; i <= L; i++) {
        for (int j = 1; j <= L; j++) {
            int dr = abs(i - n);
            int dc = abs(j - n);
            int d  = dr > dc ? dr : dc;
            printf("%d ", d + 1);
        }
        printf("\n");
    }
    
    return 0;
    

    }