function [fs,nf] =prime_factors_sp(v) %written by...... %this program will find
ID: 3756429 • Letter: F
Question
function [fs,nf] =prime_factors_sp(v)
%written by......
%this program will find prime factors
v=700
lf=round(v/2),tf=1;fn=1,nf(fn)=0,flag=0,
while tf<lf & v~=1
tf=tf+1
t=v/tf
while t==round(t)
if nf(fn)==0
fs(fn)=tf,flag=1,nf(fn)=1,
else
nf(fn)=nf(fn)+1
end
v=v/tf
t=v/tf
end
if flag==1
flag=0,fn=fn+1,nf(fn)=0,
end
end
end
E function [fs, nf]-prime factors sp(v) %written by some person on 09/27/2018 % this program will find prime factors v=700 1f round (v/2), tE-1:fn 1, nf (fn) o, flag o, tf-tf+1 t-v/tf while t-round (t) 2- if nf (fn) #0 else nf (fn)nf (fn) +1 end end 1 2 if flag-1 flag=0, fn=fn+1, nf (fn) =0, end 24Explanation / Answer
Answer : Here i have commented every line explanation .
function [fs,nf] =prime_factors_sp(v) %declaration of the function which have two %parameters
%written by......
%this program will find prime factors
v=700 % Here we are assigning the variable a %number of 700
lf=round(v/2),tf=1;fn=1,nf(fn)=0,flag=0,
%If function is a conditional
%ready-made function which put condition %and if that condition will true then only
%the code under if function run otherwise it %send the command to else function and if %the if function will be false then else will be %executed and here other functions values %are declared
while tf<lf & v~=1
% while is a loop conditional statement or %function which execute till the data is %correct here it will be executed till the tf is %less then If and v is not equal to 1
tf=tf+1
t=v/tf
while t==round(t)
% here round function which will round the %value of t here because we are finding prime %number factors so we can't take decimal %values
if nf(fn)==0
fs(fn)=tf,flag=1,nf(fn)=1,
else
nf(fn)=nf(fn)+1
end
v=v/tf
t=v/tf
end
if flag==1
% we have declare a variable flag so we can %use it whenever required as a condition.
flag=0,fn=fn+1,nf(fn)=0,
end
% this is the end of the if statement
end
end
% let me know in case of any query
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.