Fortran Computer Science

Write a Fortran program that reads in a set of real data of arbitrary length, assuming that the data is stored in an ASCII file with one real value per line, and which sorts that data of smallest to largest absolute value via a variation of the alternative sorting algorithm detailed below. You program should prompt the user to enter the name of the file containing the data, and should print out the list of data sorted by the absolute value of the data points to STDOUT. Do not print out the absolute values of the data but rather the original data sorted by absolute values smallest to largest. For example, if the set of data is {1.2, -4.3, -0.25, 0.15} the output data sorted by absolute values should be {0.15, -0.25, 1.2, - 4.3}. Alternative sorting algorithm for a set of data Assume the data points are denoted as . Then an algorithm for sorting data from lowest value to highest value is: 1. For : i=1,...,N: 2. Initialize the location of the minimum data item to jmin=i 3. For : j=i+1,...,N: 4. if(dj<djmin ) set jmin=j 5. End of j loop 6. if jmin ≠ i swap di and djmin 7. End of i loop You will need to modify this algorithm to sort by smallest absolute value

No answers yet

We have mentors from

Contact support