Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a MATLAB function (testPrime.m) that takes a scalar as an input argument and uses a for-loop and rem function to check whether the argument

Write a MATLAB function (testPrime.m) that takes a scalar as an input argument and uses a for-loop and rem function to check whether the argument is a prime number. testPrime(x) should return 1 if x is a prime number and 0 otherwise. Your testPrime function must behave as shown below: (user input is underlined) >> help testPrime testPrime(n) determine whether n is a prime number return true (1) if n is prime return false (0) if n is not prime >> testPrime(12) ans = logical 0

>> testPrime(7) ans = logical 1 Hint: To get a logical 1 and logical 0 as output of your function, see "help true" and "help false".

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions