[Solved] How to use nested loops to print out the the lower triangle multiplication table on c?


Completed Code

int main()
{
    int i, j, n = 10;

    // lower triangle multiplication table on c
    // printing the multiplication with the result like
    // 1x1=1 1x2=2 1x3=2 and so on.

    for (i = 1; i < n; printf("\n", i++))
        for (j = 1; j < n; j++)
            printf(i < j ? "    " : "%1dX%1d=%-2d ", i, j, i * j);

    return 0;
}

Your current code prints an upper triangle multiplication table. The easiest way to make it a lower triangle multiplication table is to reverse the j and i in the first part of the statement from printf(j < i ? " " : "%3d ", i * j);
to printf(i < j ? " " : "%3d ", i * j);

Get rid of the first for loop. It doesn’t accomplish anything.

Finally, to print with the result 1×1=1 1×2=2 etc, change the nested loop printf statement to print the i and j variables as shown!

1

solved How to use nested loops to print out the the lower triangle multiplication table on c?