Printing Pattern Using Loops

  • + 0 comments

    simple and easy answer

    for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                int min = (i<j?i:j)<(size-i-1<size-j-1?size-i-1:size-j-1)?(i<j?i:j):(size-i-1<size-j-1?size-i-1:size-j-1);
                printf("%d ", n - min);
            }
            printf("\n");
    

    takes the minimum out of i,j,size-i-1 and size-j-1, where size is 2n-1