1 / 4
Jan 2016

I'm trying to solve the 2nd problem prime generator. My solution works (no check yet) but I tought it might be a good idea to skip even numbers from (m,n) interval. And thats the point where it stops working properly. I can't guess by myself whats wrong since 2 days. Please help.

is_prime(a) checks if number is prime and returns bool.

int main(void)
{

int t;

std::cin >> t;
if (t>10)
{
    return 0;
}
for (int k=1; k<=t; k++)
{
    int m,n;

    std::cin >> m >> n;

    if(m%2==0) //without this works fine
    {          //
        m=m+1; // there is no output at all if I use theese lines
    }          //

    for(int j=m; j<=n; j+=2) //without m checked(odd/even), the j increase should be set to 1
    {
        bool status=is_prime(j);
        if(status)
        {
            std::cout << j << "\n";
        }

    }
    std::cout << "\n";
}
return 0;

}

  • created

    Jan '16
  • last reply

    Jan '16
  • 3

    replies

  • 782

    views

  • 3

    users

Yes, but the problem is Im not getting any output if I use evenodd checking. The program prints just blank lines not even equel to the number of primes that should be found

Please post your entire submission. It's impossible to tell what's wrong if you don't provide code that you presume is correct.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 17 10d

Want to read more? Browse other topics in C and C++ or view latest topics.