Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

C++ beginner, help for school project

deliviumdelivium Posts: 1Member
Hello there!

(I know that nobody want to make full new code for another people, but this is all about it, please continue reading)

I am having trouble in school with some basic and easy (not for me) C++ programming.
If you could help me, I need codes for these programs to pass a high school grade. I study IT school, but I study multimedia and presentation, but they want basic programming too and I have no idea what to do with it.

Thanks for any help guys!

Create a program, which determines every prime number in interval <1;100> and then print to screen:
Prime numbers in range 1

Comments

  • sunlotussunlotus Posts: 55Member
    edited December 2013

    A number, n, is prime if and only if it has no divisor between {2,...,rounded square(n)}. I answered a similar question here

  • zurabzurab MoscowPosts: 2Member
    edited December 2013

    here is the code:

    #include <iostream>
    using namespace std;
    
    bool isPrime(unsigned int n)
    {
         for(unsigned int i=2;i<=n/2;i++)
         {   
             if(n%i == 0)
               return false;
         }
         return true;
    }
    int main()
    {
        unsigned int UpperBound = 100;
        unsigned int LowerBound = 1;
        for(unsigned int i=LowerBound;i<=UpperBound;i++)
           if(isPrime(i))
              cout<<i<<endl;
        return 0;
    }
    
Sign In or Register to comment.