Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is

Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc.

NOTE: A prime number is a number that is only divisible by 1 and itself.

HINT: Your function should go through all integers between 2 and n, one by one, and check if that number is divisible by any number other than 1 or itself. If the number turned out to be a prime number, it should be appended to the end of the output argument vector before moving on to the next number.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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