Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use MATLAB no screenshots please and use pseudecode 14. Prime number. Prompt the

ID: 3731357 • Letter: U

Question

Use MATLAB

no screenshots please

and use pseudecode

14. Prime number. Prompt the user to input a number n. Then, determine if n is a prime number using a while loop. Ifn is not a prime number, show the divisors of n. For example, ifnis 20, the output should be “20 is not a prime number. 20 can be divided by: 2 4 5 10”. If n is 19, the output should be “19 is a prime number”. You may not use built in functions for prime numbers, such as isprime(). You can use other functions, such as rem() or mod().

Explanation / Answer

n= input ("enter number: ") %% initially set output flag to true result = true; %% iterate over all positive integers 2,3,...,n-1 %% if n is not divisible by any of these factors....it is prime if (n == 1) result = 'false'; elseif (n == 2) result = 'true'; else for i=2:n-1, if (mod(n,i)==0) result = 'false'; end end end %% return "true" or "false" instead of 1 or 0 if (result) result = n + "is a prime nunber"; display(result) else result = n + "is not a prime number"; disp(result) disp("factors are") for k = 1:n D = k(rem(n,k)==0) disp(D) end end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote