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

I need a matlab code for the problem up here! Thank you Create a sorting code wi

ID: 1854448 • Letter: I

Question

I need a matlab code for the problem up here!

Thank you

Create a sorting code without using built-in function 'sort' The code should ask users for a choice of sorting order either by 'A' for ascending, or for descending. Your program should output, original array and the sorted array Such as: Original Array is: 4 6 8 2 1 10 Array in ascending order is: 1 2 4 6 8 10

Explanation / Answer

%code snippet for ascending isp (‘INPUTS’) disp(‘Input the vector of numbers’) A=[18 7 6 15 4 13]; disp(A) %% SOLUTION % Number of entries, n n=length(A); % making (n-1) passes for j=1:1:n-1 % comparing each number with the next and swapping for i=1:1:n-1 if A(i)>A(i+1); % temp is a variable where the numbers are kept % temporarily for the switch temp=A(i); A(i)=A(i+1); A(i+1)=temp; end end end %% OUTPUT disp(‘ ‘) disp (‘OUTPUT’) disp (‘The ascending matrix is’) disp(A) %code snippet for descending isp (‘INPUTS’) disp(‘Input the vector of numbers’) A=[18 7 6 15 4 13]; disp(A) %% SOLUTION % Number of entries, n n=length(A); % making (n-1) passes for j=1:1:n-1 % comparing each number with the next and swapping for i=1:1:n-1 if A(i)
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