In this lecture, I'm going to show you how to create a simple multiplication table using nested loops.
This example will provide a basis for the slightly more advanced upcoming lecture.
If you noticed, increasing the complexity of the subjects that I'm talking about, step by step, this
will continue till the end of the class.
OK, now let's get started.
Now I'm going to show you what the multiplication table will look like at the end.
Of course, in the common line, it won't look as shiny as this, although you can do it with the help
of a little bit of comment line magic, but it would be an overkill for now.
So our multiplication table will be colorless.
Now, let's learn how to build this program step by step.
Now I'm going to show you how to create the header first.
Let's take a look at this in the ED.
OK, let's first print the X letter like this, if umpty printf person fifes.
X. OK, I typed this person five s were like this, so it will be five characters white, OK, five
years sets the printing waits for this verb so the print F. will print four spaces.
Then it will print the X character this way that X will be aligned to the right.
OK, ok, now let's create a loop or printing the numbers for I zero ai less than an equal to five increment
I.
OK now I'm going to print the numbers.
Printf percent five The and I.
OK, now let's print another new line here to separate the rest of the table from this other.
OK.
All right.
The Heather is right.
Now, let me run it.
It looks good to me, as you can see, X and the each number here are five characters.
What this why are used five in the printf just before.
So the line here beautifully.
By the way, while in here, let's make this magical number five constant.
OK, I'm going to use it a few times in the card.
All right, brother.
Now it's time to create this column on the left.
OK, let's take a look at this in the editor again.
All right, now I'm going to type another loop here to print the vertical column like this.
Inside, I'm going to print a number like this using the five again.
OK, since this is a vertical column, so I'm going to print another new line here.
All right, you might ask why I didn't type this new line inside the printer directly, you will see
why in the next step.
OK.
OK, now let's take a look at the table again.
I think it looks good.
Heather's off the table.
OK, now it's time to create the inner circles of this table where the real multiplication will happen.
This is where the next loop comes into the scene inside the loop.
I'm going to create another loop and loop and inside the nested loop, I'm going to multiply the numbers
to create the inner cells of the multiplication table.
All right, let's take a look at it in the according Ed.
Now, I'm going to create the nicest loop in here right inside the loop.
Now I'm going to loop four or five times again.
OK, now I'm going to print the inner circle of the table again with five words verb.
Now I need to print the multiplication like this.
I multiplied by.
This is why this printer was here, by the way, after each it prints a new line, Rembrandts.
As you can see now, it's done great.
Let's check the results.
For example, three multiplied by three is nine, four multiplied, four is sixteen, five multiplied
by five.
Twenty five.
It works the correct.
All right, our multiplication table is ready, cool.
Now it's your turn.
Here are a few challenges for you create a dynamic table by getting the size of the multiplication table
from the command line as an argument, you would need to convert it to a number, of course.
Then, for example, if the user passes five as an argument, then you will create them five x five
multiplication table or the user passes 10 than the table size will be 10x that.
As a bonus, exercise creates more tables like four division addition and subtraction.
You can create separate programs for each one.
Good luck.
But that's all for now.
See in the next picture, my.