有没VB.NET编程的高手啊?

来源:百度知道 编辑:UC知道 时间:2024/05/28 10:24:00
我有几个题目想请教
急!!!
编个程序:求和S=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)

Sub Main()
Dim n As Integer
Dim sum, nsum As Integer 'sum 记录总和,nsum记录1+2+..N的和
Console.WriteLine("please input n")

Dim tmpStr As String
tmpStr = Console.ReadLine()
'判断是否是int类型的,
'IsNumeric(tmpStr)判断是否是数字类型,InStr(tmpStr, ".") 判断是否有小数点
If IsNumeric(tmpStr) And InStr(tmpStr, ".") < 1 Then
n = CType(tmpStr, Integer)
Else
MsgBox("not a valid integer!")
Exit Sub
End If

nsum = 0
sum = 0
For i As Integer = 1 To n
nsum = nsum + i
sum = sum + nsum
Next

Console.WriteLine("the sum is : " & sum.ToString & " press enter to exit...")
Console.ReadLine()
End Sub

n = 5 'n值可任意
x = 0
y