Purchase Solution

c++ Prime Number

Not what you're looking for?

Ask Custom Question

Hi, I need some assistance with this assignment. It is dealing with pointers. I have attached the assignment and the specs. I have learned how to code and to declare pointers and that is about all I know really. Help would be appreciated, thanks!

CS 318

Prime Numbers?

You are to find all the prime numbers between 90,000 and 100,000 and print them out.

One way to do this (the way you will have to do this) is fill an array with the values from 1 to 100,000. Start with 2 and go thru the array and every 2nd location in the array zero it out. You just eliminated any value that is divisible by 2. Now move to the next value (after 2) which will be 3, and go thru the array and zero out every 3rd location of the array. You just eliminated any number divisible by 3. Now move to the next location after 3 which is 4, and you see it is zero. Skip it because you have eliminated all multiples of 4 by eliminating multiples of 2. So move to the next (5) and eliminate multiples of 5. (Be sure not to zero out the 2,3 and 5 etc since they are prime numbers, just their multiples.) So if the next location is not 0, then traverse through the array and eliminate its multiples. Do this for the entire array.

You do not have to loop from 1 to 100,000. Find what value you can stop at in this algorithm which is much less than 100,000.

Print out the nonzero values in the array and that will be the prime numbers. Print out the numbers 7 per line and make sure they line up on the last digit. (setw(8)???)

You are to use an array for the data and use pointers to move through the array to solve this problem. The only place to use the [ ] is in the declaration, no [ ] syntax in any other code in the program.

Attachments
Purchase this Solution

Solution Summary

The expert examines a c++ prime number.

Purchase this Solution


Free BrainMass Quizzes
C# variables and classes

This quiz contains questions about C# classes and variables.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.