Print nine-nine multiplication table
Printing the nine-nine multiplication table is mainly to use the nested use of loops. To print the nine-nine multiplication table, you must first clarify what needs to be controlled by each loop.
1×1 1×2 1×3 1×4 ……
2×2 2×3 2×4 ……
3×3 3×4 ……
…… (n×m) One
level control m, one level control n is enough It can be done, Xiao Nian has a look at the code.
#include<stdio.h>
int main()
{
int i = 1;
int n = 1;
for (i = 1; i <= 9;i++)
{
int pro = 0;
int j = n;
while (j <= 9)
{
pro = i*j;
printf("%2d * %2d = %2d ", i, j, pro);
++j;
}
printf("\n");
++n;
}
}
In the output of this code, the output domain width is controlled (%2d * %2d = %2d), and the code output can be controlled to be neat and easy to watch.