Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 1 . A prime number ( or a prime ) is a natural number that has exactly two distinct natural number divisors: 1 and
Problem A prime number or a prime is a natural number that has exactly two distinct natural number divisors: and itself. The purpose of this problem is to write a function say its name is check.prime to check whether or not a given natural number is a prime. Unless you want to use some other more advanced method, you can write your function based on the socalled "trial division" method. The idea is as follows. For a positive integer n one only needs to test whether is a multiple of each integer between and If is a multiple of any of these integers then it is a composite number and not a prime; if it is not a multiple of any of these integers then it is a prime. Of course, you can use other methods. For example, you can check how many factors has. If has exactly factors must be positive integers less than or equal to then is a prime.
The input of check.prime should be a positive integer and the output should be a list containing a logic variable called result and a character variable called report, which tells if the input is a prime. Specific requirements are implied from the following examples.
a If one feeds anything but a positive integer, assign NA to result and report will be "Error! The input must be a positive integer".
b We know is a prime number. Implementing check.prime will yield a T or TRUE for result and "The input IS a prime number." for report.
c Implementing check.prime will yield a F or FALSE for result and "The input IS NOT a prime number." for report.
Complete the following tasks and present your output.
i Implement your R function with and one by one and show your results.
ii Implement ; check.prime for three times and display your ontput.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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 Started