Saturday, January 31, 2009

Code for triangle numbers and their factors!!!

Module Module1
Sub Main()
Dim counter As Integer
'add another variable!
Dim diff As Integer = 1
Dim totalFactors As Integer = 0
Dim factorCounter As Integer
For counter = 1 To 60000
'Console.WriteLine(counter)
For factorCounter = 1 To counter
If counter Mod factorCounter = 0 Then
totalFactors = totalFactors + 1
End If
Next
If totalFactors > 50 Then
Console.WriteLine(counter)
End If
counter = counter + diff
diff = diff + 1
totalFactors = 0
Next

'1, 3, 6, 10, 15, 21, 28
'print out the first 10 triangle numbers!
Console.ReadLine()
End Sub
End Module

No comments: