this isn't the ideal solution, but it'll give you an idea of how to do it.

I have compiled this on MSVC++ 6.

Code:

#include <iostream.h>
#include <math.h>
int main(void)
{
int i = 0;
// we are assuming that numerator >= denominator
int numerator = 9;
int denominator = 12;
int simplified = 0;
int newNumerator = numerator;
int newDenominator = denominator;
while(!simplified)
{
int i = 0;
for(i = 2; i < newNumerator; i++)
{
// if they are both divisible by the number
if(newNumerator % i == 0 && newDenominator % i ==0)
{
// divide both by the number
newNumerator /= i;
newDenominator /= i;
// reset i to make sure that the exit condition is met properly
i = 0;
break;
}
}
// if we've made it all the way through the loop, we have no more factors
if(i == newNumerator)
{
simplified++;
}
}
cout << "The simplifed version of " << numerator << "/" << denominator;
cout << " is " << newNumerator << "/" << newDenominator << endl;
return(0);
}

hope this helps

U.