C language implementation of "multiplication tables"

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.