![]() |
|
#1
|
|||
|
|||
Need help for simple prime number questionThe question is to Write a C++ program that takes an integer n and displays the first prime number after n.
Your program should output n itself in case n is prime. Sample 1: Enter an integer: 17 17 Press any key to continue . . . Sample 2: Enter an integer: 63 67 Press any key to continue . . . Sample 3: Enter an integer: 12345678 12345701 Press any key to continue . . . my code is CPP / C++ / C Code:
I can test and generate if input is a prime number ,but get stuck with how to generate the first prime number after input which is not a prime number. plz for help!!! Last edited by LuciWiz : 04-Apr-2007 at 12:47.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: need help for simple prime number questionQuote:
You could try something like this: Make a boolean function that tests whether its argument is a prime number. The function doesn't print anything out; it returns "true" if the argument is a prime number, and "false" if not: CPP / C++ / C Code:
Then your main program can look something like this: Code:
As a matter of style, I made my output statements a little more verbose than your assignment. I suggest that you make your output exactly as the assignment requires. A few runs for mine might look like: Code:
Regards, Dave Last edited by davekw7x : 04-Apr-2007 at 10:38.
|
|
#3
|
|||
|
|||
Re: need help for simple prime number questionYou may want to rethink your algorithm somewhat, but here is a very simple example of what I think you're trying to accomplish:
CPP / C++ / C Code:
Output: Code:
:davis: |
|
#4
|
|||
|
|||
Re: need help for simple prime number questioncheers ,guys .....i am fully understand that ....!many thanks
|
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| i have a question about the number of players you can have when hosting games. | brandon1482 | Computer Software Forum - Games | 1 | 24-Feb-2007 13:08 |
| Converting a number amount to text | Godzilla | CPP / C++ Forum | 5 | 31-Mar-2006 11:38 |
| Program Needed: Perfect Number Program in C language | koool_kid | C Programming Language | 12 | 02-Dec-2005 14:02 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 20:25 |
| Help w/ prime # determination | crystalattice | C Programming Language | 17 | 18-Apr-2004 21:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The