Noobie to C::B

• October 16th, 2013, 09:34 AM
millw0715
Noobie to C::B
I'm pretty new to programming in general and I have a very basic idea of of how everything works. I'm going through practice questions to help improve my programming and I cannot seem to figure out the following, it's got me stumped.

A prime number is any positive integer that is evenly divisible only by itself and
one. The smallest prime number is two. Devise a method to calculate prime
numbers based on divisibility. Write a program that calculates and displays all
the prime numbers up to a maximum number specified by the user. For
example, if the user wished to see all the primes up to 25, the program would
provide the following list: 2, 3, 5, 7, 11, 13, 17, 19 and 23. The program needs
to display the list in an appropriate way.

Could anyone lend a helping hand? Thanks.
• October 16th, 2013, 09:43 AM
VictorN
Re: Noobie to C::B
How would you do it using a piece of paper and a pencil?
• October 16th, 2013, 10:11 AM
2kaud
Re: Noobie to C::B
Hint. This topic has cropped up before on these codeguru forums with solution programs provided. You should be able to find them using a forum search.
• October 16th, 2013, 11:26 AM
GCDEF
Re: Noobie to C::B
Probably better to figure it out himself than just copy and paste somebody's solution without learning anything.

Victor is putting you on the right path. List the steps you'd need to take before you try to write any bode.
• October 16th, 2013, 04:01 PM
razzle
Re: Noobie to C::B
Quote:

Originally Posted by millw0715
A prime number is any positive integer that is evenly divisible only by itself and
one.

One convenient way to check whether an integer n is evenly divisible by another integer m is by way of the modulo operator %. The modulo operator gives the rest after integer division. If it's 0 the integers are evenly divisible, like

Code:

```if (n%m == 0) {   // n is evenly divisible by m (so if m is in the range from 2 to n-1 then n cannot be a prime) }```