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

Write a MatLab program that will do the following: 1. Read a number from the key

ID: 3931313 • Letter: W

Question

Write a MatLab program that will do the following: 1. Read a number from the keyboard. 2. If the number is 0 or less, or non-integer, display an error and ask for that number again, until a positive integer is given. 3. Find all of its prime factors. 4. Output all of these prime factors on the screen, all appearing on a single line, followed by the message ‘End of program.’ 5. Use loops to accomplish your tasks. Do NOT use functions such as factor(), isprime(), primes(), etc. Do NOT use vectors or matrics

Explanation / Answer

z=input('Enter your positive number: ');
while( z < 0 )
fprintf('%d Not a valid postive number.Please Try again..!! ', z);
z=input('Enter your positive number: ');
end
num=z;
str='';
for i = 2 : num
s = 0;
% Finding the factors for a number and checking whether it is prime or not
while num/i == floor(num/i)
num = num/i;
s = s + 1;
end
  
if s > 0
str = [str ' ' num2str(i)];
  
if num == 1
break
end
end

end
fprintf('Prime Factors of %d are %s ',z,str);
fprintf(' End of program.');

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