Question: Use matlab or octave to code. DO NOT USE while loops. Use for loops, if statements, vectors, matrices or functions. Test out all the cases

Use matlab or octave to code. DO NOT USE while loops. Use for loops, if statements, vectors, matrices or functions. Test out all the cases so you know that your coding works for everything.
3. (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 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) 13_P = 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
