Thursday, January 19, 2012

10001st prime number

/*

 * bhatt.umang7@gmil.com

 */

/*

 * 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 10001st prime number?

 */



#include<iostream>


using namespace std;

bool isPrime(long no)
{
    bool bval = true;

    for(long i = 2 ; i < no ; i++)
    {

        if ( no % i == 0 )
        {

            bval = false;
            break;
        }
    }
    return bval;
}

int main()

{

    long count = 0 ;

    long no = 2 ;
    while (true)
    {

        if (isPrime(no)==true)
        {
            count++;
            if (count == 10001)
            {

                break;
            }
        }
        no++;
    }
    cout << no << "\n";

}

No comments:

Post a Comment