C language: implement a function, print the multiplication table, and specify the number of rows and columns in the table.
Implement a function to print the multiplication table. specify the number of rows and columns in the table, input 9, output 9*9, OUTPUT 12, and output 12*12. Program:
# Include <stdio. h> void mul (int n) // multiplication {int I, j; for (I = 1; I <= n; I ++) {for (j = 1; j <= I; j ++) {printf ("% d * % d = %-2d", I, j, I * j ); // 2 in % 2d indicates two output cells, and the number is aligned to the back, that is, the right alignment; %-2d indicates the left alignment of the number} printf ("\ n ");}} int main () {int n = 0; printf ("Enter the rows in the multiplication table:"); scanf ("% d", & n); mul (n ); return 0 ;}
Result: Enter the rows in the multiplication table: 121*1 = 12*1 = 2 2*2 = 43*1 = 3 3*2 = 6 3*3 = 94*1 = 4 4*2 = 8 4*3 = 12 4*4 = 165*1 = 5 5*2 = 10 5*3 = 15 5*4 = 20 5*5 = 256*1 = 6 6*2 = 12 6*3 = 18 6*4 = 24 6*5 = 30 6*6 = 367*1 = 7 7*2 = 14 7*3 = 21 7*4 = 28 7*5 = 35 7*6 = 42 7*7 = 498*1 = 8 8*2 = 16 8*3 = 24 8*4 = 32 8*5 = 40 8*6 = 48 8*7 = 56 8*8 = 649*1 = 9 9*2 = 18 9*3 = 27 9*4 = 36 9*5 = 45 9*6 = 54 9*7 = 63 9*8 = 72 9*9 = 8110*1 = 10 10*2 = 20 10*3 = 30 10*4 = 40 10*5 = 50 10*6 = 60 10*7 = 70 10*8 = 80 10*9 = 90 10*10 = 10011*1 = 11 11*2 = 22 11*3 = 33 11*4 = 44 11*5 = 55 11*6 = 66 11*7 = 77 11*8 = 88 11*9 = 99 11*10 = 110 11*11 = 12112*1 = 12 12*2 = 24 12*3 = 36 12*4 = 48 12*5 = 60 12*6 = 72 12*7 = 84 12*8 = 96 12*9 = 108 12*10 = 120 12*11 = 132 12*12 = 144 press any key to continue...