?
Solved

Prime Numbers and Twin Primes in C...

Posted on 2003-02-25
6
Medium Priority
?
667 Views
Last Modified: 2011-10-03
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
Comment
Question by:JohnPryce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

by:gj62
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

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

Expert Comment

by:TheBeaver
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
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

by:jmcg
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].

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
 

Accepted Solution

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

SpazMODic
EE Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question