Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Prime Numbers and Twin Primes in C...

Posted on 2003-02-25
Medium Priority
670 Views
Hi,

I'm trying to write a program that calculates all of pairs of numbers in the range 1-400 in which the first number is any prime number, and the second is 2X the first number + 1, and is also prime, then prints each pair.

Does anybody know how this might be done?

Thanks!

--J.Pryce.
0
Question by:JohnPryce

LVL 6

Expert Comment

ID: 8018622
Yes, but it sounds like homework, which is against the house-rules to post solutions to.  If you make an attempt, we will certainly try to help you where you run into difficulty.

That said, a google search on prime numbers source code usually will give you a fair starting point...
0

LVL 6

Expert Comment

ID: 8018634
You can also look under Sieve of Eratosthenes, but you probably knew that already...
0

LVL 1

Expert Comment

ID: 8021716
If you ask me this is a trick question as any number that is 2X something is divisable by 2 and therefore NOT PRIME.

Then again, if you are saying...
second_number = (first_number * 2) + 1

...then the only result (if you think about it) would be 1 and 3. Wouldn't it?
0

LVL 85

Expert Comment

ID: 8022235
1 is not prime
but if we are saying
second_number = (first_number * 2) + 1
then there's 2 and 5, or 3 and 7, or 5 and 11,  etc
0

LVL 20

Expert Comment

ID: 10018405
Nothing has happened on this question in over 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
delete, forfeit points [homework].

jmcg
EE Cleanup Volunteer
0

Accepted Solution

SpazMODic earned 0 total points
ID: 10050507
PAQed - no points refunded (of 30)

SpazMODic
EE Moderator
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were smallâ€¦
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and infâ€¦
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
###### Suggested Courses
Course of the Month13 days, 4 hours left to enroll