int numerator, denomenator; // set these to something
int smallest; // holds the smaller of the two variables
int gcf; // greatest common factor
// determine which number is smallest, doesn''t matter if equal
if ( numerator >= denomenator )
{ smallest = numerator; }
else
{ smallest = denomenator; }
for ( int i = smallest; i > 0; i++ )
{
// if both numbers divide evenly, then it is divisible by i
if ( ( numerator % i == 0 ) && ( denomenator % i == 0 ))
{ gcf = i; }
}
it might help a bit if you add:
cout << gcf;
also, you need to name int i earlier in your coding. putting it in the middle of the program slows the program down. 1 more thing, why do you have:
if ( numerator >= denomenator )
{ smallest = numerator; }
else
{ smallest = denomenator; }
shouldn''t it be:
if ( numerator <= denomenator )
{ smallest = numerator; }
else
{ smallest = denomenator; }
int smallest; // holds the smaller of the two variables
int gcf; // greatest common factor
// determine which number is smallest, doesn''t matter if equal
if ( numerator >= denomenator )
{ smallest = numerator; }
else
{ smallest = denomenator; }
for ( int i = smallest; i > 0; i++ )
{
// if both numbers divide evenly, then it is divisible by i
if ( ( numerator % i == 0 ) && ( denomenator % i == 0 ))
{ gcf = i; }
}
it might help a bit if you add:
cout << gcf;
also, you need to name int i earlier in your coding. putting it in the middle of the program slows the program down. 1 more thing, why do you have:
if ( numerator >= denomenator )
{ smallest = numerator; }
else
{ smallest = denomenator; }
shouldn''t it be:
if ( numerator <= denomenator )
{ smallest = numerator; }
else
{ smallest = denomenator; }
No electrons were harmed in the creation of this message. THINK -- it gives you something to do while the computer is down. To err is human. To really screw things up you need a computer.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement