![]() |
|
[SOURCE]Prime Number Calculator - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework) +--- Thread: [SOURCE]Prime Number Calculator (/Thread-SOURCE-Prime-Number-Calculator) |
[SOURCE]Prime Number Calculator - 1llusion - 02-07-2011 Hi ![]() So, Recently I had some bad marks from maths coz I'm not very interested in the subject we are doing school... Anyway, my teacher agreed that if I amaze him somehow, he will give me a bonus to my marks ![]() So I made this little prime number calculator. It's not the MOST efficient way, but also not least. Function: Code: Function IsPrimeNumber(ByVal i As Double) As Boolean
MySqrt = Sqrt(i) 'Uses math law to make the number smaller. Forgot how the operation is called T_T
For a As Integer = 2 To MySqrt
If i Mod a = 0 Then Return False
Label9.Text = a
Next
Return True
End FunctionUsage: Code: For i As Double = NumericUpDown2.Value To NumericUpDown1.Value 'From what number to what number
If IsPrimeNumber(i) Then ListBox1.Items.Add(i) 'Adds prime numbers
NextNOTE: Yes, I did get the bonus
|