struct Rational {
int q; // Numerator
int p; // Denominator
};
void print_array(Rational a[], int n)
{
for (int i=0; i<n; i++)
cout << a[i].q << '/' << a[i].p << ' ';
cout << endl;
}
int main()
{
const int N = 4;
Rational a[N];
cout << "Please input 4 rational numbers" << endl;
for (int i=0; i<N; i++)
{
cin >> a[i].q >> a[i].p;
}
cout << endl;
print_array(a, N);
exchange_sort(a, N, cmp);
print_array(a, N);
return 0;
}
Please input 4 rational numbers
7 3
1 5
6 5
4 3
7/3 1/5 6/5 4/3
1/5 6/5 4/3 7/3