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
- 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".
Step by Step Solution
3.46 Rating (159 Votes )
There are 3 Steps involved in it
C code to create and test the function findprime include u... View full answer
Get step-by-step solutions from verified subject matter experts
