Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

C code to create and test the function findprime include u... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Programming questions