#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,388
Default Finding primes

Hi all,

I need a formula or function that when I input a number then it will return
that prime. For example if I input 100 then I will get the 100th prime number.

Your assistance would be much appreciated.

D
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Finding primes

http://support.microsoft.com/?kbid=202782
--
Gary''s Student - gsnu200814


"Dave" wrote:

Hi all,

I need a formula or function that when I input a number then it will return
that prime. For example if I input 100 then I will get the 100th prime number.

Your assistance would be much appreciated.

D

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,388
Default Finding primes

Hi,

Thanks for that. I was a bit suspicious when the site gave an incorrect
definition of a prime number and while I don't fully understand the code when
I ran it it gave an incorrect answer.

d



"Gary''s Student" wrote:

http://support.microsoft.com/?kbid=202782
--
Gary''s Student - gsnu200814


"Dave" wrote:

Hi all,

I need a formula or function that when I input a number then it will return
that prime. For example if I input 100 then I will get the 100th prime number.

Your assistance would be much appreciated.

D

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Finding primes

Dave,

Why am I not surprised that the Microsoft website incorrectly defines a
prime number and then goes on to provide code that confirms the lack of
understanding. Perhaps you should submit as a suggestion to MS that it
corrects its site.

In the meantime try this. Alt+F11 to open VB editor. Right click 'This
Workbook' and insert module and paste the code below in. With a number in A1
call with

=nthprime(A1)
With 100 in a1 it will return the 100th prime.

It starts getting a bit slow with large numbers but it's the fastest way I
know.

Function NthPrime(PrimeRequired As Long) As Long
Dim i As Long
If PrimeRequired 0 Then
For x = 2 To 100000000
If (x < 2 And x Mod 2 = 0) Or x < Int(x) Then GoTo 100
For i = 3 To Sqr(x) Step 2
If x Mod i = 0 Then GoTo 100
Next
foundprime = foundprime + 1
If foundprime = PrimeRequired Then
NthPrime = x
Exit Function
100
End If
Next
On Error GoTo 0
End If
End Function


Mike

"Dave" wrote:

Hi,

Thanks for that. I was a bit suspicious when the site gave an incorrect
definition of a prime number and while I don't fully understand the code when
I ran it it gave an incorrect answer.

d



"Gary''s Student" wrote:

http://support.microsoft.com/?kbid=202782
--
Gary''s Student - gsnu200814


"Dave" wrote:

Hi all,

I need a formula or function that when I input a number then it will return
that prime. For example if I input 100 then I will get the 100th prime number.

Your assistance would be much appreciated.

D

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding a Value SueK Excel Discussion (Misc queries) 3 September 21st 08 07:27 PM
Finding the value of x bpiepkorn Excel Worksheet Functions 4 July 26th 07 04:02 PM
Finding Row fak119 Excel Discussion (Misc queries) 3 May 18th 06 05:54 PM
Finding value tkaplan Excel Discussion (Misc queries) 2 October 21st 05 08:19 PM
finding the "end" Julia New Users to Excel 2 September 1st 05 02:38 AM


All times are GMT +1. The time now is 09:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"