[Children's Day] Ninety-Nine Multiplication Table

Article Directory


insert image description here

foreword

Thank you very much for clicking into this special article. Time flies, and before I know it, I have come to my 30th Children's Day.
I am very happy. When I was young, I played with my friends at school, and then I grew up and went crazy with my brothers. Very lucky! Now there are still companies that take our old babies to play together.
Because my uncle is a programmer, I came into contact with programming relatively early, and before I knew it, it was my fifteenth year of learning programming.
I remember when I first started learning, my uncle told me that the program is actually very simple. It's you telling the computer, if so, do something... if not, do something else.
Then naturally, I slowly started my programming path from if...else..., and it was out of control...It was a
coincidence. At that time, the most troublesome but very useful topic was placed in front of me "Nine-Nine Multiplication Table".
Loops are also a very useful and important part of programs, so today I will share with you how to use loop nesting to write a "Ninety-Nine Multiplication Table" at the end of the June 1 event.

cycle

In C#, there are for, foreach, while, do while... Here, the for loop is used to write

First, let’s look at the basic structure of the for loop:
Picture 1
when the program runs to this line, the for keyword will be looped. The content of the loop body is separated by a semicolon, and the program will execute it. Step 1: Execute <1 initialization condition> Step 2: Determine whether <2 Judgment condition> is true, and if so, execute the loop body Step 3: Execute the content of <3 loop body>
After
< 4 iteration condition
> repeat
2 3 4 2 3 4... until it is judged whether <2 judgment condition> is false, jump out of the loop and execute the following code.





Note:
When the continue; keyword is encountered in the loop body, the code behind the loop body will not be executed, and it will directly go to <4 iteration condition> to continue executing the next loop. When the break; keyword is encountered in the loop body, the code behind the loop body will not be executed, and the current loop will be directly executed, and the following code will be
executed
.


nested loop

So how do we print the ninety-nine multiplication table?
How do we print the multiplication table? The multiplication table needs to be composed of several numbers and symbols. You can notice that there are certain rules.
AXB = AB
AXC = AC AXD = AD
... and so on, I believe everyone can understand this
, so we need to use nested loops, look at the code below:
insert image description here

当第一次执行<1外循环体>时,i为1
此时内循环体变量j由1开始,因此通过<3内判断条件> 判断,<2内循环体>中循环一次.
j由1到1就结束
当第二次执行<1外循环体>时,i为2
此时内循环体变量j还是由1开始,因此通过<3内判断条件> 判断,<2内循环体>中循环两次.
j由1到2就结束
当第三次执行<1外循环体>时,i为3
此时内循环体变量j还是由1开始,因此通过<3内判断条件> 判断,<2内循环体>中循环三次.
j由1到3就结束
以此类推…
使用string将变化的数字串起来并输出,得到以下效果::
picture 3
至此一个《九九乘法表》就打印结束了。

epilogue

In our knowledge system, this is a simple but very crucial knowledge
. It is a bit long-winded. This knowledge often reminds me of the way the math teacher taught me patiently...
to the children who will never grow up.
Thanks for reading

Guess you like

Origin blog.csdn.net/ww1351646544/article/details/131188729