__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 product, 1 × 5 or 5 × 1, involve 5 itself. However, 6 is composite because it is the product of two numbers (2 × 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.

__TYPICAL SOURCE CODE RELATED__

[c]

/*

This code is worked on from http://notmyfaultsblog.blogspot.in/2010/06/project-euler-problem-7-in-c.html

Modified a little for standards by Jeffrin Jose T ahiliation@yahoo.co.in

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

*/

#include <stdio.h>

#include <math.h>

int isPrime(int test)

{

int i;

int calculateTo = (int) sqrt(test);

for(i = 3; i<=calculateTo; i+=2)

{

if(test%i==0)

return 0;

}

return 1;

}

int main()

{

int howHigh=10001;

int counter=1;

int i;

while (1)

{

for(i=3 ; ; i+=2)

{

if( isPrime(i) )

counter++;

if(counter==howHigh)

{

printf("%d\n", i);

return 0;

}

}

}

return 1;

}

[/c]

__TYPICAL OUTPUT SESSION RELATED__

[bash]

$gcc -lm tpn.c -o tpn

$./tpn

104743

$

[/bash]

LINKS

https://en.wikipedia.org/wiki/Prime_number

https://en.wikipedia.org/wiki/Factorization