"Multiplication table" in C Language"

Source: Internet
Author: User

"Multiplication table" in C Language"
The difficulty in using C language to implement a multiplication table lies in how to control the data output format, which is a deep understanding of nested for loops. First, the outer loop is assigned once, and the inner loop is executed once. For the multiplication table program, when the outer loop is 1 and the inner loop is also 1, a row and a column are printed; when the outer loop is 1 and the inner loop is 2, two columns, and so on are printed. For the sake of beauty, print in "%-4d" format, "-" indicates the left alignment, and "4d" indicates that the output Integer Data occupies at least four places, in fact, the most two are here, and the remaining two are 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 ++) // The inner for loop control line {printf ("% d * % d = %-4d", j, I, I * j); // % 4d indicates four digits, insufficient space filling} //-4 indicates left-aligned printf ("\ n");} return 0 ;}

 


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.