Simple multiplication table
Published Oct 13, 2009
Updated Oct 13, 2009
Only 8 .NET snippets? Guess I better put at least SOMETHING into it. Anyways, this is a simple console application, put it in a new console application project (I use Microsoft Visual Basic 2008 Express Edition).
It'll ask you for a number and then generate a multiplication table based on that number.
I know it's not the most advanced stuff in the world.. but hey, someone could learn from it (comments were included).
PS: For loops rock. Why does mIRC not have them?
' Declare variables.
Dim tablenum, var As Double
' Start of the Do loop that allows us to continually input new numbers.
' Ask user for an input and set tablenum to it.
Console.Write("Enter the number you want to see multiplications for: ")
tablenum = Console.ReadLine()
' Check if the number is going to cause an overflow and crash the program.
If (tablenum >= 999999999999999999) Then
Console.WriteLine("That number is too long - please use a smaller one...")
' If everything is OK, procede to output the multiplication table.
' A basic for loop that will output the line 12 times.
'"Next" automatically increases var by one on each iteration.
For var = 1 To 12
Console.WriteLine(var & " * " & tablenum & " = " & var * tablenum & ".")
' Make it loop endlessly so that the user can keep inputting numbers until they close the program.
Loop Until 1 = 2