Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I am executing this program iam getting timeout.
How to solve this problem and I want to print first 10,000 primes?
Thanks in advance....

my code is


C#
void main()
{
    int i,j; int count;
    for(i=2;i<100000;i++)
    {   count=0;
        for(j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
                ++count;
        }
        if(count==0)
            printf("%d\n",i);
    }
}
Posted
Updated 25-Jun-13 21:26pm
v3
Comments
Rajesh Anuhya 25-Jun-13 4:53am    
Home work?
N Shiva 25-Jun-13 5:07am    
No, a problem on some coding site...just trying 2 solve.

1 solution

You program runs fine on my system (WinXP). Has your system scarce resources?
Please note: there a more clever ways for computing prime numbers (see, for instance "Generating Primes" at Wikipedia[^].
 
Share this answer
 
Comments
N Shiva 25-Jun-13 5:09am    
As my system is win8, I can't install any 'C' compiler. For this program I am using online compiler codepad.org
enhzflep 25-Jun-13 5:12am    
What do you mean? Why can't you install a compiler?
N Shiva 25-Jun-13 5:22am    
give me link to download Turbo C software, which works on windows8.
CPallini 25-Jun-13 5:33am    
Turbo C is obsolete. You might use, for instance, Visual Studio Express Edition.
enhzflep 25-Jun-13 5:41am    
Elephant off idiot. I asked you a question, two in fact.

What do you respond with? 'gimme linkz for the TurboC'

(1) Turbo C is _old_
(2) Turbo C(3.0) was old and crap back in 1993 - when I had a copy on 5 1/4" floppies
(3) Turbo C supports a max memory allocation of about a megabyte.
(4) See points 1 - 3 again.

Oh, did I mention that it's old and crap. Certain countries have foolishly syandardised upon this compiler in educational institutions since it is really old and has low system requirements. This makes it not only possible, but also feasible to run on aging and inexpensive hardware. With a computer running windows 8, neither of those 2 considerations apply to you.

Here, take this instead: It's Code::Blocks. Makes console apps, & windows apps. You can easily allocate 1024 MB of mem - 1 gig - to a program with it. It also supports multimedia extensions and optimizations available for the cpu in your system, not just a 486 or thereabouts.
Code::Blocks
(Get codeblocks-12.11mingw-setup.exe)
Note: you'll also need to get ResourceEditor if you want to draw dialogs visually.
The download is about 97MB - VS Express is many hundred.
VS has a debugger that works, CB has an editor that is nice and responsive.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900