Prime number

how can i get the largest prime number ?
any help please
This question reminds me of Wikipedia's list of numbers. In this article they say "This list is incomplete, You can help by expanding it with reliably sourced entries."

The largest prime number is pretty close to infinity.

If you want some methodologies for finding prime numbers:
1. Loop through an ever-increasing test number.
2. Check if it is prime by modding it with the numbers before it (test%i)
3. If it is prime, set the largest prime equal to this, then continue with the next test number.

Something like this I suppose would help get the LARGEST prime:

1
2
3
4
5
6
7
8
9
10
for (int i = 1; true; i++)
{
    bool is_prime = true;

    for (int j = 1; j<i/2; j++)
        if (i%j==0) is_prime = false;

    if (is_prime)
        cout << i << ", ";
}


This code will run forever until you stop it. It will continuously find new prime numbers and output them to the console.

Edit: Post number 200 baby!
Last edited on
You can't. There are infinitely many primes so there is no largest prime.
what if i had like 185 numbers ?
and i have to make a c++ program that tells me which of these numbers is the largest prime number ?
Last edited on
1
2
3
for(int i=0; i < max_primes; ++i)
    if(primes[i] > largest_prime)
        largest_prime = primes[i];
Last edited on
Topic archived. No new replies allowed.