diff options
Added my solutions to Sem. 03 exercises
1 files changed, 30 insertions, 0 deletions
| -rw-r--r-- | Year 1/Programming introduction/Solutions Sem. 03/04. Primes_In_Interval.cpp | 30 |
diff --git a/Year 1/Programming introduction/Solutions Sem. 03/04. Primes_In_Interval.cpp b/Year 1/Programming introduction/Solutions Sem. 03/04. Primes_In_Interval.cpp new file mode 100644 index 0000000..a1510da --- /dev/null +++ b/Year 1/Programming introduction/Solutions Sem. 03/04. Primes_In_Interval.cpp @@ -0,0 +1,30 @@ +#include <iostream> +#include <cmath> + +using namespace std; + +int main() +{ + int a, b; + cin >> a >> b; + + if (a < 2) a = 2; + + for (int i = a; i <= b; i++) + { + bool isPrime = true; + int rootOfI = sqrt(i); + for (int j = 2; j <= rootOfI; j++) + { + if (i % j == 0) + { + isPrime = false; + break; + } + } + + if (isPrime) + cout << i << " "; + } + cout << endl; +} |
