Is a Number Prime?

Easy

Read an integer and print 17 is prime or 18 is not prime with the number in place. Numbers below 2 are not prime. Test divisors from 2 upward with a loop whose bound is written as i <= n / i rather than i * i <= n, so that the test is defined for every int including 2147483647, and leave the loop with break at the first divisor. If the number cannot be read, print invalid input and return 1.

Success Criteria

Your code must pass 9 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

How did you find this exercise?

Your rating helps us improve the content.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron