Question: Write a Matlab function, called testprime, that takes one input argument and uses a for - loop and rem function to check whether its argument

Write a Matlab function, called testprime, that takes one input argument and uses a for-loop and rem function to check whether its 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:
>> help testprime
testprime checks if its argument is a prime
testprime(x) is 1 if x is a prime, 0 otherwise.
Author:
>> 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
 Write a Matlab function, called testprime, that takes one input argument

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!