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

prompt= input(\'Enter values you would like to sort (seperate vaules with commas

ID: 3549892 • Letter: P

Question

prompt= input('Enter values you would like to sort (seperate vaules with commas and enclosed values with square brackets)');

prompt2= input('How would you like it sorted, press 0 for ascending or press 1 for descending', 's');

B = prompt;

n=length(B);

if prompt2 == 1;


for j=1:n

for i=1:n-j

if B(i)>B(i+1)

continue;

else

temp=B(i);

B(i)=B(i+1);

B(i+1)=temp;

end

end

end

else

for j=1:n

for i=1:n-j

if B(i)>B(i+1)

temp=B(i);

B(i)=B(i+1);

B(i+1)=temp;

end

end

end

end

disp (B)


How do I output the sorted array one item at a time using fprintf

Explanation / Answer

%add following lines after the end of the code

l=length(B);

for k=1:l

fprintf('%d ',B(k));

end