发表于:2013/4/4 15:53:57
#0楼
九九乘法,比较经典的例子。看起来似乎很简单,关键是理解算法,以及如何实现算法。
老规矩,老鸟飘过,分享给需要学习的朋友.....
1.矩形输出
Sub Main()
Dim a As Integer
Dim b As Integer
For a = 1 To 9
For b = 1 To 9
Console.Write("{0}*{1}={2}{3}", a, b, a * b, vbTab)
Next
Console.WriteLine()
Next
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
End Sub
2.三角形输出 I
sub main()
Dim i As Integer
Dim j As Integer
For i = 1 To 9
For j = 1 To 9
If i > j Then
Console.Write("{0}*{1}={2}{3}", i, j, i * j, vbTab)
End If
If i = j Then
Console.WriteLine("{0}*{1}={2}", i, j, i * j)
End If
Next
Next
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
End sub
3.三角形输出 II
Sub main()
Dim m As Integer
Dim n As Integer
For m = 1 To 9
For n = 1 To 9
If m <= n Then
Console.Write("{0}*{1}={2}{3}", m, n, m * n, vbTab)
End If
Next
Console.WriteLine()
Next
End Sub
4.三角形输出 III
Sub main()
Console.WriteLine("01234567891012345678901234567890123456789~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Dim x As Integer, y As Integer, p As Integer = 0
For x = 1 To 9
For y = 1 To 9
If x <= y Then
Console.Write("{0}*{1}={2}{3}", x, y, x * y, vbTab)
Else
For v = 0 To 7
Console.Write(Chr(32))
Next
End If
Next
Next
End Sub
5.三角形输出 IV
Sub main()
Dim i As Integer, j As Integer
For i = 1 To 9
For j = i To 9
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End Sub
6.三角形输出 V
Sub main()
Dim i As Integer, j As Integer
For i = 1 To 9
For j = 1 To i
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End sub
7.三角形输出 VI
Sub main()
For i = 9 To 1 Step -1
For p = 1 To i
For x = 0 To 7
RichTextBox1.Text = RichTextBox1.Text & Chr(32)
Next
Next
For j = i To 9
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End sub
8.三角形输出 VII
Sub main()
For i = 1 To 9
For p = i To 9
For x = 0 To 7
RichTextBox1.Text = RichTextBox1.Text & Chr(32)
Next
Next
For j = 1 To i
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End Sub
9.矩形分段输出 VIII
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer, j As Integer, m As Integer, n As Integer, p As Integer, q As Integer
For j = 1 To 9
For i = 1 To 3
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
For n = 1 To 9
For m = 4 To 6
RichTextBox1.Text = RichTextBox1.Text & m & "*" & n & "=" & m * n & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
For q = 1 To 9
For p = 7 To 9
RichTextBox1.Text = RichTextBox1.Text & p & "*" & q & "=" & p * q & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End Sub
老规矩,老鸟飘过,分享给需要学习的朋友.....
1.矩形输出
Sub Main()
Dim a As Integer
Dim b As Integer
For a = 1 To 9
For b = 1 To 9
Console.Write("{0}*{1}={2}{3}", a, b, a * b, vbTab)
Next
Console.WriteLine()
Next
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
End Sub
2.三角形输出 I
sub main()
Dim i As Integer
Dim j As Integer
For i = 1 To 9
For j = 1 To 9
If i > j Then
Console.Write("{0}*{1}={2}{3}", i, j, i * j, vbTab)
End If
If i = j Then
Console.WriteLine("{0}*{1}={2}", i, j, i * j)
End If
Next
Next
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
End sub
3.三角形输出 II
Sub main()
Dim m As Integer
Dim n As Integer
For m = 1 To 9
For n = 1 To 9
If m <= n Then
Console.Write("{0}*{1}={2}{3}", m, n, m * n, vbTab)
End If
Next
Console.WriteLine()
Next
End Sub
4.三角形输出 III
Sub main()
Console.WriteLine("01234567891012345678901234567890123456789~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Dim x As Integer, y As Integer, p As Integer = 0
For x = 1 To 9
For y = 1 To 9
If x <= y Then
Console.Write("{0}*{1}={2}{3}", x, y, x * y, vbTab)
Else
For v = 0 To 7
Console.Write(Chr(32))
Next
End If
Next
Next
End Sub
5.三角形输出 IV
Sub main()
Dim i As Integer, j As Integer
For i = 1 To 9
For j = i To 9
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End Sub
6.三角形输出 V
Sub main()
Dim i As Integer, j As Integer
For i = 1 To 9
For j = 1 To i
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End sub
7.三角形输出 VI
Sub main()
For i = 9 To 1 Step -1
For p = 1 To i
For x = 0 To 7
RichTextBox1.Text = RichTextBox1.Text & Chr(32)
Next
Next
For j = i To 9
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End sub
8.三角形输出 VII
Sub main()
For i = 1 To 9
For p = i To 9
For x = 0 To 7
RichTextBox1.Text = RichTextBox1.Text & Chr(32)
Next
Next
For j = 1 To i
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End Sub
9.矩形分段输出 VIII
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer, j As Integer, m As Integer, n As Integer, p As Integer, q As Integer
For j = 1 To 9
For i = 1 To 3
RichTextBox1.Text = RichTextBox1.Text & i & "*" & j & "=" & i * j & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
For n = 1 To 9
For m = 4 To 6
RichTextBox1.Text = RichTextBox1.Text & m & "*" & n & "=" & m * n & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
For q = 1 To 9
For p = 7 To 9
RichTextBox1.Text = RichTextBox1.Text & p & "*" & q & "=" & p * q & vbTab
Next
RichTextBox1.Text = RichTextBox1.Text & Chr(13)
Next
End Sub
[此贴子已经被作者于2013/4/6 18:20:54编辑过]