Int main ()
{
Int a, b, c, I;
Printf (" please enter the number two \ n ");
The scanf (" % d % d ", & amp; A, & amp; B);
If (a{
C=a,
A=b,
B=c.
}
For (I=b; I> 0; I -)
{
If (a % I==0 & amp; & B % I==0)
Printf (" the greatest common divisor: % d \ n ", I);
}
C=a * b;
C=c/I;
Printf (" LCM % d \ n ", c);
return 0;
}
CodePudding user response:
Modified as follows, for your reference:# include & lt; stdio.h>
Int main (int arg c, char * argv [])
{
Int a, b, c, I, y.
Printf (" please enter the number two \ n ");
The scanf (" % d % d ", & amp; A, & amp; B);
If (a{
C=a;//this is ";" , not ", "
no.A=b;
B=c.
}
for(i=1; i<=b; I++)
{
If (a % I==0 & amp; & B % I==0) y=I;//add a variable y, and record the common factor
}
Printf (" the greatest common divisor: % d \ n ", y);
C=a * b;
C=c/y;
Printf (" LCM: % d \ n ", c);
return 0;
}
CodePudding user response:
The cause of the error is in the greatest common divisor, I value to 0,c=c/I;
Will be an error,
Change the method
for (I=b; I> 0; I -)
{
If (a % I==0 & amp; & B % I==0)
{//-- -- -- -- -- -- -- add -- -- -- -- -- -- -- -- -- -- -- -- -- --
Printf (" the greatest common divisor: % d \ n ", I);
break;//-- -- -- -- -- - after get the greatest common divisor, end the for loop -- -- -- -- -- -- -- -- -- --
}//-- -- -- -- -- -- -- -- -- -- - add -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
}
Vc + + 6.0 environment debugging c + +
Vc + + 6.0 is my favorite, no one