# largest number prime number that can be produced...

This is a discussion on largest number prime number that can be produced... within the C Programming forums, part of the General Programming Boards category; my code:: can anyone suggest how to make the output larger????? Code: #include<stdio.h> #include<limits.h> #include<float.h> int main() { unsigned int ...

1. ## largest number prime number that can be produced...

my code::

can anyone suggest how to make the output larger?????

Code:
```#include<stdio.h>
#include<limits.h>
#include<float.h>
int main()
{
unsigned int num,tmp,suc=1,i;
num=UINT_MAX;
do
{
suc=1;
tmp=num;
for(i=2;i<=tmp/2;i++)
{
if(tmp%i==0)
{
suc=0;
break;
}
}
num--;
}while(suc==0);
printf("%u",num+1);
getchar();
return 0;
}```

2. what do you mean by lager?

3. larger means the biggest prime number possible

4. you can try
unsigned long
unsigned long long (not supported by all compilers)
some library for working with extreamly long numbers

5. Originally Posted by ElemenT.usha
larger means the biggest prime number possible
http://www.prime-number.org

6. "the biggest prime number possible" means nothing. There is no limit beyond which all numbers are composite. The only possible thing you can mean is the largest prime number known to man.
You don't have a hope of getting anywhere remotely near the largest primes known to man using such an archaic and naieve algorithm. It would literally take Millennias (thousands of years)! No I'm not exagerating.

Hell, I've written a decent bigint library, but even I gave up hope of doing realistically useful primality testing.
Even getting into the upper realms of 64-bit territory just gets ridiculous with how long it takes using the algorithm you provided. Faster algorithms like your typical sieve of Eratostheses overflow conventional PC memory with this size too.

I'm sorry, but unless you use a special purpose library, you simply wont be able to do what you want!

You could try understanding the Primality testing algorithms in Wikipedia, but be warned, you'd best become a maths professor first.

7. actually i need to use a time function and find the largest possible in 2sec..
so can you tell me some means to speed up my process

8. It could be possible for 64 bits but only with very advanced methods.
As iMalc pointed out, do a little Wiki study, try implementing the suggested methods.
It might turn out to be a difficult task, and you probably need to know good 'C' to get it to work and be correct also, even for someone who knows good 'C'.

9. Originally Posted by ElemenT.usha
actually i need to use a time function and find the largest possible in 2sec..
so can you tell me some means to speed up my process
Well, how about telling us that to being with?
So, how does that work? You need to explain furthur. Do you just start writing out primes, and after 2 seconds your program is killed off and the highest prime you outputted during that time is the winner?

You can get some improvement by storing a list of primes as you go, and testing against primes in the list that are less than the square root of the number, instead of testing all odd numbers.
Note that this is still significantly slower than the Sieve of Eratostheses, but past a certain point it requires less extra memory. I'm not going to help much beyond that because this is obviously a test of some kind.