Challenge 2: Check for Prime Number
In this lesson, the user will check if a number is prime or not using recursion.
We'll cover the following
What is a prime number?
A prime number is a number greater than 1, that has only two divisors: 1 and the number itself. The first few prime numbers are:
Composite numbers are numbers that are not prime, that is, have divisors other than zero and itself
The numbers and are neither prime nor composite.
All the numbers are either prime or composite, except for and .
Problem Statement
Write a recursive function, named isPrime()
that checks if a number is prime or not.
Instructions
- The function should take two integers as input.
- The function should return boolean return if true and the number is prime. Should return if false and the number is not prime.
- The function should be recursive.
Sample Input: 7
Sample Output: 1
Sample Input: 9
Sample Output: 0
Good luck!
Note: Some test cases will pass by default and you need to pass all for the solution to be considered correct.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.