How to use nested loops to print out the the lower triangle multiplication table on c? -
i want print multiplication result, 1x1=1 1x2=2 1x3=3 , on.
thanks,
int main() { int i, j, n = 10; (i = 1; <= n; printf("%d\n", i++)) (j = 1; j <= n; j++) printf(j < ? " " : "%3d ", * j); return 0; }
completed code
int main() { int i, j, n = 10; // lower triangle multiplication table on c // printing multiplication result // 1x1=1 1x2=2 1x3=2 , on. (i = 1; < n; printf("\n", i++)) (j = 1; j < n; j++) printf(i < j ? " " : "%1dx%1d=%-2d ", i, j, * j); return 0; } your current code prints upper triangle multiplication table. easiest way make lower triangle multiplication table reverse j , in first part of statement printf(j < ? " " : "%3d ", * j); printf(i < j ? " " : "%3d ", * j);
get rid of first loop. doesn't accomplish anything.
finally, print result 1x1=1 1x2=2 etc, change nested loop printf statement print , j variables shown!
Comments
Post a Comment