![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Create a program that computes all the prime numbers less than 10,000Create a program that computes all the prime numbers less than 10,000 by storing them in an array and then printing them out, 10 primes to a row. (A prime is a positive integer greater than 1 whose only factors are 1 and itself).
(a)To test if a positive integer N is prime, one can divide N by all integers from 2 up to the square root of N. As soon as you find one factor of N, you can stop. If you get all the way to without finding a factor, then N is prime. (b)write the program in the more efficient manner where you divide N by all primes less than or equal to , stopping if and when you find a factor. This will require you to store the primes in an array as you compute them, and then for each integer N check to see if any elements of the array are factors of N. This comparison will be inside a “for” or “while” loop. c)You may enter the first element of the array, say prime[1] = 2, directly in the program. ------------------------------------------------------------------ I want to print all prime number from 2 to 10000. 10 primes to row. my code is below CPP / C++ / C Code:
Last edited by admin : 03-Apr-2009 at 01:25.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
|||
|
|||
Re: Create a program that computes all the prime numbers less than 10,000A few braces here and there and the whole program went haywire.
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Create a program that computes all the prime numbers less than 10,000The code does not run. I fix my code but it still show one error.
Compiler error is that Code:
The code is CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: Create a program that computes all the prime numbers less than 10,000Please use code tags next time.
Please indent your code. You also need to include Code:
Quote:
|
|
#5
|
|||
|
|||
Re: Create a program that computes all the prime numbers less than 10,000I will use cod tags next time.
thank you very much! I got it |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Guidelines for posting requests for help - UPDATED! | WaltP | C Programming Language | 1 | 11-Nov-2007 22:05 |
| Barcode reader code problem | copa_21 | C Programming Language | 5 | 13-Oct-2006 01:40 |
| User defined headers | davis | Miscellaneous Programming Forum | 6 | 16-Feb-2006 19:40 |
| Could Someone Please Explain This Code To Me | HelpMePlease | C Programming Language | 3 | 26-May-2004 23:46 |
| something wrong with this code | loon | MySQL / PHP Forum | 5 | 07-Jul-2003 06:55 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The