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

  1. 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:

  1. Check if the number is greater than 1, then
  2. Initialize a for loop starting from 2 and ending at the number.
  3. Check if the number is divisible by 2.
  4. 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

1 Expert Approved Answer
Step: 1 Unlock

C code to create and test the function findprime include u... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!