If I understand continued fractions correctly, you don't need to compute the GCD of the numerator and the denominator.
The following program does the job:
#include <iostream>
#include <utility>
std::pair<int, int> getFraction(int a[], int size)
{
int n = 1;
int d = a[size-1];
for(int i = size - 2; i >= 0; i--)
{
int nextd = d*a[i] + n;
n = d;
d = nextd;
}
// When we are done, d is the numerator and n is the denominator.
return std::make_pair(d, n);
}
int main()
{
int a[] = {4, 2, 6, 7};
int size = sizeof(a)/sizeof(a[0]);
std::pair<int, int> f = getFraction(a, size);
std::cout
<< "Numerator: " << f.first
<< ", Denominator: " << f.second << std::endl;
}
Output of running the program:
Numerator: 415, Denominator: 93