Advertisement

i

Started by December 19, 2001 07:14 PM
1 comment, last by aeleneski 22 years, 11 months ago
i [Edited by - aeleneski on April 24, 2006 11:22:58 PM]
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; }
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.
Advertisement
declaring varibles in the middle of the code vs at the top does not slow anything down at all. whoever told you that lie is quite ignorent or does not understand the mechanics of a compiler.

This topic is closed to new replies.

Advertisement