C++ beginner, help for school project - Programmers Heaven

Howdy, Stranger!

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

Categories

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.