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
Step: 1
C code to create and test the function findprime include u...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
C++ Primer Plus
Authors: Stephen Prata
6th Edition
978-0321776402, 0321776402
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App