The difficulty in implementing multiplication tables in C is how to control the format of the data output, which is a deep understanding of nested for loops. First, the outer loop is assigned one time, the inner loop executes once, and for the multiplication table This program, The outer loop is 1, the inner loop is 1 o'clock, one row is printed, The outer loop is 1, the inner loop is 2 o'clock, and a row of two columns is printed 、、、、、、 and so on. Then for the sake of aesthetics, in the printing of "%-4d" format printing, "-" symbol for left alignment, "4d" for the output of the shaping data accounted for at least 4 bits, in fact, up to two bits, the remaining two bits filled with spaces.
The C language code is as follows:
# include <stdio.h>int main () { int i,j; for (i=1; i<=9; i++) //outer for Loop control column { for (j=1; j<=i; j++) //inner for loop control line { printf ("%d*%d=%-4d", j, i, i*j); //% 4d represents 4 bits, not enough space to fill } //-4 means left-aligned printf ("\ n"); } return 0;}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/73/83/wKiom1X_2qXxe2p9AAE3TuB-Ckg734.jpg "title=" 20150921165646.png "alt=" Wkiom1x_2qxxe2p9aae3tub-ckg734.jpg "/>
little knowledge of dry goods :*p++ self-increment p or the variable that p points to?
The suffix + + and-operator are inherently higher priority than the prefix-to-eye operation, where + + and p combine precedence over * and P, so *p++ and * (p++) are equivalent, it increases p and returns the value pointed to by the P-increment (i.e., the first to go to the content and then the pointer p to be self-added). To increment the value that P points to, use the (*p) + + and use ++*p if the order of the side effects does not matter.
This article is from the "Nobody" blog, please be sure to keep this source http://814193594.blog.51cto.com/10729329/1696822
C language implementation of "multiplication tables"