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

Write coments on the program on how the program works and how to run it. Please

ID: 3756623 • Letter: W

Question

Write coments on the program on how the program works and how to run it. Please comment every line

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 24

Explanation / Answer

First of all , i would like to say that program is wrong and incomplete as it doesnt give any output .

function [fs,nf] =prime_factors_sp(v) // the function is not a keyword in either of the languages

%written by...... //comments are usually specified in '//' or '/* */'  
%this program will find prime factors so % is wrong symbol to declare comment.

v=700 //since v is an interger .it should be declared as " int v=700; "

lf=round(v/2),tf=1;fn=1,nf(fn)=0,flag=0, //here also declaration os variables is missing . for using round function its library should be included i.e include <math.h> to function .

while tf<lf & v~=1 //While condition checking whether var tf is less than var lf and var v is not equal to 1


tf=tf+1 //if the condition is true var tf will be added to itself and value of var t will be changed as per the equation .
t=v/tf
while t==round(t)   //If the above while condition is false it will skip above above two statements and check for this while statement and according enter the loop .But since the syntax is wrong the output will show error .

if nf(fn)==0 //here nf(n) is shown as a function or data type is not clear
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 // according to the program if the value of flag is 1 then the program is ended and flag value will become 0
flag=0,fn=fn+1,nf(fn)=0,   
end //If the function was specified in the program then the value of (fs,nf) , would have returned as the prime factors of v
  
end

end //End of While (the first one)

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