Write a function called find_prime that takes a number from the user as the input and returns
Fantastic news! We've Found the answer you've been seeking!
Question:
- Write a function called "find_prime" that takes a number from the user as the input and returns true if the number is prime and false otherwise.
For example:
Input -> 5 Output -> true
Definition of a prime number: a whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1
(e.g., 2, 3, 5, 7, 11).
Your algorithm should have the followings:
- Check if the number is greater than 1, then
- Initialize a for loop starting from 2 and ending at the number.
- Check if the number is divisible by 2.
- Repeat till the number-1 is checked for.
In case, the number is divisible by any of the numbers, the numberish not prime.
Else, it is a prime number.
If the number is less than 1, then returns "cannot find the prime".
Related Book For
Posted Date: