![]() |
|
#1
|
|||
|
|||
Program to find biggest prime number from user inputHey there.. I'm have to finish a program for tomorrow. What I got to do is this:
The guide will put a number between 1 and 10000 I need to find all primes into the number he put, not print, but save them and print the biggest primes of this primes and the second biggest. For example the guide put 10 I will say him "There is 4 primes" The biggest is 7 and the second is 5... What I've already made is this : CPP / C++ / C Code:
sorry for bad english, and thanks for your help. hugs from brazil Last edited by admin : 03-Oct-2009 at 22:59.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|||
|
#2
|
||||
|
||||
Re: Need some help to finish a program !!Read the Guidelines and repost so we can read your code.
__________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#3
|
|||
|
|||
Re: Program to find biggest prime number from user inputQuote:
If you need to save all of the primes, then allocate an array, say primes and, inside your loop, whenever you find a prime number, store its value in primes[cont] (and, of course increment cont each time, as you already do). After you have found all of them, print the last two values in the array. If you only need to count the number of primes that you found and don't need to save them all, but only print the largest two, then you can try something like 1. Declare integer variables biggest, second 2. Get user input. You have already done this, but if the user enters an invalid number, you should either abort the program or go back and ask the user for to try again. 3. Make a loop that finds all prime numbers up to and including the user input, and increments a counter for each one that is found. You have already done this, but you need to keep track of the largest and second largest numbers found as you go through the loop CPP / C++ / C Code:
Maybe you can make it a little more elegant, but that is one way to approach the problem. Regards, Dave |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Equation solver | RazoR | C Programming Language | 3 | 18-May-2008 10:24 |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 11:13 |
| BOOKEEPING program, HELP!! | yabud | C Programming Language | 10 | 17-Nov-2006 04:48 |
| Help with a complex program | lordfuoco | C++ Forum | 5 | 24-Jun-2006 07:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The