473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Generating prime pairs in C

4
Hi, I missed a couple classes due to being sick this past week and I am having trouble getting steered in the right direction for my programming assignment. I'd ask the professor for help but he has a total of four hours during the week for office hours, all of which I have a class. But anyways...

Write a C program that produces prime pairs. At the start, user is prompted to input a positive integer less than 100,000 after which the program prints all the prime pairs in the range 3 through <= N (user input). The program should check the user input to be a value greater than 5 and less than 100,000.

So an example of the running program would look something like the following...

{{
Enter an integer > 5 and < 100,000 and the program will print all the prime pairs up to that value: -4

The integer must be > 5 and < 100,000: 120000

The integer must be > 5 and < 100000: 400

List of prime pairs from 3 to 400

3 - 5
5- 7
11- 13
17- 19
. .
. .
. .
. .
347- 349
}}

Now I know that I need to use a ceiling function and I want to do something like...
i<=(ceil(sqrt(double)n)); i++)

but, I really don't know where to start, or end for that matter with this program.

I could use some help, thanks.
Apr 24 '08 #1
7 2199
oler1s
671 Expert 512MB
Now I know that I need to use a ceiling function and I want to do something like...
but, I really don't know where to start,
Those must be some amazing talents if you can tell what arbitrary line of code you need to write before you have even begun...

But, always try to break down your program into chunks you can manage. Start by breaking down your program into some big, big general steps it must take. Do that. What steps does your program take?

Let me give you an example. If I write a program that sums integers from 1 to a user specified number, by program steps would be 1. Ask the user what the upper limit is and 2. Add up all the numbers from 1 to that upper limit.

It sounds kinda pointless to do this, but then when you say you have no idea where to start, this is what I make you do to understand.
Apr 24 '08 #2
tmitt
4
I did that.

I want to prompt the user to enter their number, scan their number, and then I want my function to test it using the ceiling function.

Now I am not sure if I need to create a prototype beneath the include section and before the int Main function.

Void ceil(x); is the prototype I used but it seems far fetched to use this. Then after the ceiling function is used and it checks for prime numbers but I also don't think my function is entirely correct.

I also keep messing up my loops and its frustrating! =)
Apr 24 '08 #3
Laharl
849 Expert 512MB
If you've #included <math.h>, you have the ceil() function built in. It'll return an integer.
Apr 25 '08 #4
tmitt
4
Okay so no prototype...but I'm still at such a loss for the rest of the program.
Apr 25 '08 #5
tmitt
4
To generate from three instead of using a ceiling function I could use n-(n-i) with i set to 3 and i++
Apr 25 '08 #6
scruggsy
147 100+
To generate from three instead of using a ceiling function I could use n-(n-i) with i set to 3 and i++
Stop thinking in C. You're not ready to code until you have an algorithm.
Instead, write down the steps required to find prime pairs, in general. How would you do it if you didn't have a computer?
Once you have the steps, you can translate them into a language the computer will understand. If you have trouble there, post your algorithm and your code.
Apr 25 '08 #7
oler1s
671 Expert 512MB
Instead of musing about the content of your program, why don't you actually sit down and write down various parts of it?

I want to prompt the user to enter their number
Why don't you try writing this part up first?
Apr 25 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
11
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not...
6
by: Poul Møller Hansen | last post by:
I have made a stored procedure, containing this part for generating a unique reference number. SET i = 0; REPEAT SET i = i + 1; SELECT RAND() INTO reference FROM SYSIBM.SYSDUMMY1; SET...
18
by: baltimoredude1 | last post by:
Hi I was writing a simple code to generate the first 100 prime numbers. Everything looks fine to me except the output of the program. What's wrong with it? I am attaching the program as well as...
25
by: johnmsimon | last post by:
i need to develop a code that finds a prime right number between 2 and 100000. and print one line of text that indicates if the int. is right prime. i am in beginning programing so complex is...
60
by: rhle.freak | last post by:
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers...
7
by: newstips6706 | last post by:
1, 2, 3, 5, 7... PRIME Numbers ________________________________ Definitions What is a PRIME Number ?
2
by: vrkraju | last post by:
import java.io.*; import java.lang.*; class Prime { public static void main(String args) { int a; int b; String s; try{
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.