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: 3549889 • 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 a for ascending or press d for descending', 's');
if prompt2 == 'a' || prompt2 == 'A';
B = prompt;
n=length(B);
for j=1:n
   for i=1:n+1
    if B(i)>B(i+1);
        temp=B(i);
        B(i)=B(i+1);
        B(i+1)=temp;
    end
    end
end
else prompt2== 'd' | prompt== 'D';
     for j=1:n
         for i=1:n+1
        if B(i)>B(i+1);
        temp=B(i);
        B(i)=B(i+1);
        B(i+1)=temp;
        end
         end
     end
end
disp (B);
     

Please check and fix

Explanation / Answer

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 a for ascending or press d for descending', 's');

B = prompt;

n=length(B);

if prompt2 == 'd' || prompt2 == 'D';


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)