Rational Number (2)

  1. Using the struct and the functions defined in the previous exercise, design a program which reads 20 rational numbers, print them out, sort them in ascending order, and print out the sorted sequence.
  2. You may test with this data set or this data set. Or, you may supply the 20 rational numbers by yourself.
  3. The main function may look like:
    int main()
    {
        Rational A[N];
    
        read_rationals(A, N);
        print_rationals(A, N);
    
        sort_rationals(A, N);
        print_rationals(A, N);
    
        return 0;
    } 
  4. The program may run as follows:
    8/7 9/9 7/6 2/5 1/5 6/1 2/4 4/2 7/6 3/3 1/3 4/1 4/1 5/4 2/2 2/6 9/1 7/4 8/2 4/5
    1/5 2/6 1/3 2/5 2/4 4/5 2/2 3/3 9/9 8/7 7/6 7/6 5/4 7/4 4/2 4/1 4/1 8/2 6/1 9/1