Multiplication table using for loop

[size=1][/size]Please help me how to make a program that would directly print the multiplication table using [b]for loop[/b].

the required output will be like this

[hr]
* 1 2 3 4 5 6 7 8 9 10
1 1 2 3 4 5 6 7 8 9 10
2 2 4 6 8 10 12 14 16 18 20
3 3 6 9 12 15 18 21 24 27 30
4 4 8 12 16 20 24 28 32 36 40
5 5 10 15 20 25 30 35 40 45 50

or

1 2 3 4 5
+-----+-----+-----+-----+-----+
1 | 1 | 2 | 3 | 4 | 5 |
+-----+-----+-----+-----+-----+
2 | 2 | 4 | 6 | 8 | 10 |
+-----+-----+-----+-----+-----+
3 | 3 | 6 | 9 | 12 | 15 |
+-----+-----+-----+-----+-----+
4 | 4 | 8 | 12 | 16 | 20 |
+-----+-----+-----+-----+-----+
5 | 5 | 10 | 15 | 20 | 25 |
+-----+-----+-----+-----+-----+


hope you understand what this output should be.. because it's hard to do it here correctly since it is my very first time in this site.
thank you guys..

Comments

  • : [size=1][/size]Please help me how to make a program that would
    : directly print the multiplication table using [b]for loop[/b].
    :

    I hope my reply is not too late.

    Basically, you'd want to make two nested loops
    [code]
    Dim MaxNum As Integer
    Dim x As Integer, y As Integer

    For y = 1 To MaxNum
    For x = 1 To MaxNum
    [italic]print x * y[/italic]
    Next x
    Next y
    [/code]
    Here, x represents the column (or horizontal number) and y the row (or vertical number).
    The trick now is to turn it into a nice table, with a column and row header, and spacing between the numbers etc.
    First try if you can manage to fill a string with all the multiples, and see if you can make that look nice (don't worry about the rest of the table at first). Once you get that working, add a piece of code before the for loops to print the column header,. Then before each x-loop, but inside the y-loop print the y-th row header.
    I could tell you more, but I'm affraid I'd give you the entire code if I do. Should I? Because if you want to try yourself, I don't want to ruin that chance for you.
    I'll give you one more tip: use this code framework to create a string (using a lot of string concatenations). If you want to go to a new line, concatenate vbCrLf to the string (sString = sString & vbCrLf).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion