| veeyik (32) | |||
|
i am doing a question that asked to code a program to display FIRST 100 palindromic number. i already have the function isPrime and isPalindrome. but i dont know how to loop the first 100. this is my main code.
can anyone correct me please? | |||
|
|
|||
| iHutch105 (947) | ||
|
You probably want something a little different to what you have. Your approach is looping up to fixed values. A better approach would be to loop until you get what you need. I'll give you some pseudocode to give you a hint.
EDIT: No idea why I wrote 99 instead of 100. | ||
|
Last edited on
|
||
| veeyik (32) | |||
How about this?
| |||
|
|
|||
| iHutch105 (947) | |
|
That's not going to work because you're incrementing j no matter what. That loop needs to end when you've found 100 primes, not after 100 iterations regardless. You should only need one loop here; a while loop that loops until you've got your prime numbers. That while loop needs only one if statement inside of it. Edited earlier response due to a mistake. I'm a little reluctant to give out the code for this because it seems like it may be school/homework. | |
|
Last edited on
|
|
| veeyik (32) | |||
Is this correct?
| |||
|
|
|||
| iHutch105 (947) | |
| Have you tested it? Does it produce 100 palindromic primes? | |
|
|
|
| threeright (22) | |||
|
you don't have to make the loop end at a number you can do something like
| |||
|
Last edited on
|
|||
| veeyik (32) | |
| Yes it is correct thank you =) | |
|
|
|