Skip to content

Instantly share code, notes, and snippets.

@TyOverby
Created June 23, 2011 23:04
Show Gist options
  • Save TyOverby/1043845 to your computer and use it in GitHub Desktop.
Save TyOverby/1043845 to your computer and use it in GitHub Desktop.
Module Module1
Private Delegate Sub Numbering()
Sub Main()
Dim Fns As Numbering
'Fns = New Numbering(AddressOf FnOdd)
'Fns()
'Fns = New Numbering(AddressOf FnEven)
'Fns()
'Fns = New Numbering(AddressOf FnFours)
'Fns()
Fns = New Numbering(AddressOf FnPrime)
Fns()
End Sub
Sub FnOdd()
Console.WriteLine("Enter a number for N")
Dim n As Integer = Console.ReadLine
Console.WriteLine("The odd numbers between 1 and N are")
Dim x As Integer = 1
Do
System.Console.WriteLine(x)
x = x + 2
Loop While (x <= n)
Console.WriteLine("Press enter")
Console.ReadKey()
End Sub
Sub FnEven()
Console.WriteLine("Enter a number for N")
Dim n As Integer = Console.ReadLine
Console.WriteLine("The even numbers between 1 and N are")
Dim x As Integer = 2
Do
System.Console.WriteLine(x)
x = x + 2
Loop While (x <= n)
Console.WriteLine("Press enter")
Console.ReadKey()
End Sub
Sub FnFours()
Console.WriteLine("Enter a number for N")
Dim n As Integer = Console.ReadLine
Console.WriteLine("The numbers between 1 and N that are perfectly divisible by 4 are")
Dim x As Integer = 1
Do
x = x + 1
If x Mod 4 = 0 Then
Console.WriteLine(x)
End If
Loop While (x <= n)
Console.WriteLine("Press enter")
Console.ReadKey()
End Sub
Sub FnPrime()
Dim n, x, i As Integer
Console.WriteLine("Enter a number for N")
n = Console.ReadLine
x = 1
Console.WriteLine("The prime numbers between 1 and {0} are: ", n)
Dim bPrime As Boolean
For x = 1 To n
bPrime = True
Dim f As Integer
For f = 2 To x-1
'Console.WriteLine("Checking {0} MOD {1}",x,f)
If x Mod f = 0 Then
bPrime = False
'Console.WriteLine("{0} MOD {1} FALSE",x,f)
End If
Next
If bPrime = True Then
Console.WriteLine(x)
End If
Next
Console.ReadKey()
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment