
{"id":16041,"date":"2014-11-07T14:39:59","date_gmt":"2014-11-07T14:39:59","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=16041"},"modified":"2014-11-07T14:39:59","modified_gmt":"2014-11-07T14:39:59","slug":"how-to-write-a-program-to-find-10001st-prime-number","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2014\/11\/07\/how-to-write-a-program-to-find-10001st-prime-number\/","title":{"rendered":"A program to find 10001st prime number ?"},"content":{"rendered":"<p><u>ABOUT PRIME NUMBER<\/u><\/p>\n<pre>\nA prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 \u00d7 5 or 5 \u00d7 1, involve 5 itself. However, 6 is composite because it is the product of two numbers (2 \u00d7 3) that are both smaller than 6. Primes are central in number theory because of the fundamental theorem of arithmetic: every natural number greater than 1 is either a prime itself or can be factorized as a product of primes that is unique up to their order.\n<\/pre>\n<p><u>TYPICAL SOURCE CODE RELATED<\/u><br \/>\n[c]<br \/>\n\/*<br \/>\nThis code is worked on from http:\/\/notmyfaultsblog.blogspot.in\/2010\/06\/project-euler-problem-7-in-c.html<br \/>\nModified a little for standards by Jeffrin Jose T ahiliation@yahoo.co.in<\/p>\n<p>By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.<br \/>\nWhat is the 10 001st prime number?<\/p>\n<p>*\/<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;math.h&gt;<\/p>\n<p>int isPrime(int test)<br \/>\n{<br \/>\nint i;<br \/>\nint calculateTo = (int) sqrt(test);<\/p>\n<p>for(i = 3; i&lt;=calculateTo; i+=2)<br \/>\n{<br \/>\nif(test%i==0)<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>return 1;<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\nint howHigh=10001;<br \/>\nint counter=1;<br \/>\nint i;<\/p>\n<p>while (1)<br \/>\n{<br \/>\nfor(i=3 ; ; i+=2)<br \/>\n{<br \/>\nif( isPrime(i) )<br \/>\ncounter++;<\/p>\n<p>if(counter==howHigh)<br \/>\n{<br \/>\nprintf(&quot;%d\\n&quot;, i);<br \/>\nreturn 0;<br \/>\n}<br \/>\n}<\/p>\n<p>}<\/p>\n<p>return 1;<br \/>\n}<br \/>\n[\/c]<br \/>\n<u>TYPICAL OUTPUT SESSION RELATED<\/u><br \/>\n[bash]<br \/>\n$gcc -lm tpn.c -o tpn<br \/>\n$.\/tpn<br \/>\n104743<br \/>\n$<\/p>\n<p>[\/bash]<br \/>\nLINKS<br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Prime_number\">https:\/\/en.wikipedia.org\/wiki\/Prime_number<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Factorization\">https:\/\/en.wikipedia.org\/wiki\/Factorization<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ABOUT PRIME NUMBER A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2014\/11\/07\/how-to-write-a-program-to-find-10001st-prime-number\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A program to find 10001st prime number ?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[1289],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16041"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=16041"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16041\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=16041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=16041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=16041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}