QUOTE(zach101 @ Dec 10 2005, 07:23 AM)

Okay i got a little further take a llook at this code and tell me what you think do i need a while loop in there?
CODE
#include<iostream.h>
//------------------------------------------------------------------------------
void Reduce(int Num, int Denom)
int Div = Num;
if (Num % Div == 0 && Div % Div == 0)
GFC = int Div
else
Div--;
//------------------------------------------------------------------------------
int main()
{
int Num, Denom;
cout << "Enter the numerator: ";
cin >> Num;
cout << "Enter the denominator: ";
cin >> Denom;
Reduce(Num, Denom);
cout << "The reduced fraction is " << Num << "/" << Denom << endl;
}
return(0);
}
To find out the GCD/GCF of two integers, you can make use of euclidean algorithm. That is, GCD(a,

= GCD(a%b,

if a>b. You can use a recursive function to find out the answer in fewer steps. The function should look like this
int GCD(int a , int

{
if (a ==

{
return a;
}
if (a * b == 0)
{
return a + b;
}
return ( a%b , b%a);
}
Hope it can help.
QUOTE(zach101 @ Dec 10 2005, 07:23 AM)

Okay i got a little further take a llook at this code and tell me what you think do i need a while loop in there?
CODE
#include<iostream.h>
//------------------------------------------------------------------------------
void Reduce(int Num, int Denom)
int Div = Num;
if (Num % Div == 0 && Div % Div == 0)
GFC = int Div
else
Div--;
//------------------------------------------------------------------------------
int main()
{
int Num, Denom;
cout << "Enter the numerator: ";
cin >> Num;
cout << "Enter the denominator: ";
cin >> Denom;
Reduce(Num, Denom);
cout << "The reduced fraction is " << Num << "/" << Denom << endl;
}
return(0);
}
To find out the GCD/GCF of two integers, you can make use of euclidean algorithm. That is, GCD(a,b ) = GCD(a%b,b ) if a>b. You can use a recursive function to find out the answer in fewer steps. The function should look like this
CODE
int GCD(int a , int b)
{
if (a == b)
{
return a;
}
if (a * b == 0)
{
return a + b;
}
return ( a%b , b%a);
}
Hope it can help.
Reply