Noobie to C::B
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Noobie to C::B

  1. #1
    Join Date
    Oct 2013
    Posts
    1

    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.

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,270

    Re: Noobie to C::B

    How would you do it using a piece of paper and a pencil?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

    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.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,047

    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.

  5. #5
    Join Date
    Jul 2013
    Posts
    201

    Re: Noobie to C::B

    Quote Originally Posted by millw0715 View Post
    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)
    }
    Last edited by razzle; October 16th, 2013 at 04:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center