Given two numbers L and R, the task is to find the prime numbers between L and R.
Input: L = 1, R = 10
Output: 2 3 5 7
Prime number between the 1 and 10 are 2, 3, 5, and 7
Input: L = 30, R = 40
Output: 31 37
Approach: The idea is to iterate from in the range [L, R] and check if any number in the given range is prime or not. If yes then print that number and check for the next number till we iterate all the numbers.
Below the implementation of the above approach:
2 3 5 7
Time Complexity: O((R-L)*N), where N is the number, and L and R are the given range.
Auxiliary Space: O(1)
Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.