(Prime Testing) A positive integer n is prime if it is greater than or equal to two and it is evenly divisible by only 1 and itself (n). Therefore, we can test this divisibility against all numbers between 2 and n – 1 to determine if a given number is prime. (In fact, this can be sped up by stopping at vn instead of n - 1.) For this problem do not use the built in isprime function (or any other function which trivializes the problem). Also, do not use the break command since it is a bad programming practice and I would like to discourage its use. is_prime Function: Input variables: • a single number representing n; if n is a positive integer, we wish to determine if it is prime, and otherwise will simply return 0 (false). Output variables: • a boolean representing whether or not the given n was prime. A possible sample case is: » is_p = is_prime(7) is p = 1 » is_p = is_prime(16) is_p = 0 » is_p = is_prime(-1) is p = 0 » is_p = is_prime(pi) is p = 0
(Prime Testing) A positive integer n is prime if it is greater than or equal to two and it is evenly divisible by only 1 and itself (n). Therefore, we can test this divisibility against all numbers between 2 and n – 1 to determine if a given number is prime. (In fact, this can be sped up by stopping at vn instead of n - 1.) For this problem do not use the built in isprime function (or any other function which trivializes the problem). Also, do not use the break command since it is a bad programming practice and I would like to discourage its use. is_prime Function: Input variables: • a single number representing n; if n is a positive integer, we wish to determine if it is prime, and otherwise will simply return 0 (false). Output variables: • a boolean representing whether or not the given n was prime. A possible sample case is: » is_p = is_prime(7) is p = 1 » is_p = is_prime(16) is_p = 0 » is_p = is_prime(-1) is p = 0 » is_p = is_prime(pi) is p = 0
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
make mathlab code

Transcribed Image Text:**Prime Testing**
A positive integer \( n \) is prime if it is greater than or equal to two and it is evenly divisible by only 1 and itself (\( n \)). Therefore, we can test this divisibility against all numbers between 2 and \( n - 1 \) to determine if a given number is prime. (In fact, this can be sped up by stopping at \(\sqrt{n}\) instead of \( n - 1 \).)
For this problem *do not* use the built-in `isprime` function (or any other function which trivializes the problem). Also, do not use the `break` command since it is a bad programming practice and I would like to discourage its use.
**is_prime Function:**
- **Input variables:**
- a single number representing \( n \); if \( n \) is a positive integer, we wish to determine if it is prime, and otherwise will simply return 0 (false).
- **Output variables:**
- a boolean representing whether or not the given \( n \) was prime.
A possible sample case is:
```
>> is_p = is_prime(7)
is_p = 1
>> is_p = is_prime(16)
is_p = 0
>> is_p = is_prime(-1)
is_p = 0
>> is_p = is_prime(pi)
is_p = 0
```
Expert Solution

Introduction
Prime number: A number is said to be prime if the number has two factors, called one and itself. Then the number is called a prime number. There will be no other factors except 1 and itself.
For example, consider 6 . The factors of the 6 are 1,2,3 and 6. It has more than two factors 1 and itself. So, 6 is not a prime number.
Consider 5, the factors of the 5 are 1 and 5. Therefore, 5 is a prime number.
Step by step
Solved in 3 steps with 3 images

Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education