diff options
feat(Week07): Add solutions
1 files changed, 24 insertions, 0 deletions
| -rw-r--r-- | Week07/Exercise11.cpp | 24 |
diff --git a/Week07/Exercise11.cpp b/Week07/Exercise11.cpp new file mode 100644 index 0000000..5e5c3e4 --- /dev/null +++ b/Week07/Exercise11.cpp @@ -0,0 +1,24 @@ +#include <iostream> + +bool isPrime(unsigned int x) { + for (unsigned int div = 2; div < x; div++) { + if (x % div == 0) + return false; + } + return x > 1; +} + +int main() { + unsigned int a, b; + std::cin >> a >> b; + + unsigned int count = 0; + while (a <= b) { + count += isPrime(a); + a++; + } + + std::cout << count << std::endl; + + return 0; +} |
