quartiles:=proc(x,m,n) local max_val, max_idx, i, j, k, q1, q2, q3, m1, m3, n1, n3; # reorder the array for k from m to n-1 do max_val:=x[k]; max_idx:=k; for i from k+1 to n do if x[i]>max_val then max_val:=x[i]; max_idx:=i; fi; od; x[max_idx]:=x[k]; x[k]:=max_val; od; print(`The array in decending order`); print(eval(x)); # find the median and index ranges for quartiles if type(n-m+1,odd) then q2:=x[(n+m)/2]; m1:=m; n1:=(n+m)/2; m3:=(n+m)/2; n3:=n; else q2:=0.5*(x[(n+m-1)/2]+x[(n+m+1)/2]); m1:=m; n1:=(n+m-1)/2; m3:=(n+m+1)/2; n3:=n; fi; # find the 1st/3rd quartile if type(n1-m1+1,odd) then q1:=x[ (n1+m1)/2 ]; q3:=x[ (n3+m3)/2 ]; else q1:=0.5*( x[(n1+m1-1)/2]+x[(n1+m1+1)/2] ); q3:=0.5*( x[(n3+m3-1)/2]+x[(n3+m3+1)/2] ); fi; print(`The 1st, 2nd and 3rd quartiles`); print(q1, q2, q3); end;