Home > Back-end > Three digits for the greatest common divisor and least common multiple, where is wrong?
Three digits for the greatest common divisor and least common multiple, where is wrong?
Time:06-09
# include
Int main () { Int a, b, c; The scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C); int n; If (a> B) { If (c> A) n=c; If (c} The else { If (b> C) n=b; The else n=c; } Do { If (a==0 n % & amp; & B==0 n % & amp; & N % c==0) {} The else n++; } while (n % a!=0 & amp; & N % b!=0 & amp; & N % c!=0); Printf (" LCM % d ", n); If (a> B) { If (b> C) n=c; If (b} The else { If (a> C) n=c; The else n=a; } Do {
If (a % n==0 & amp; & B % n==0 & amp; & C % n==0) {} The else n -; } while (a % n!=0 & amp; & B % n!=0 & amp; & C % n!=0); Printf (" the greatest common divisor % d ", n); return 0; }
CodePudding user response:
Computer no compiler, no compilation, watched the general, if there is no compilation problems, I found a doubt is: "!"="is not equal to, the program should not be inside"=="?
CodePudding user response:
You do while loop is too complex, too, is right circulation problem over there
do { If (a==0 n % & amp; & B==0 n % & amp; & N % c {==0) break; } The else n++; } the while (1);
CodePudding user response:
# include
Int main () { Int a, b, c; The scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C); int n; If (a> B) { If (c> A) n=c; If (c} The else { If (b> C) n=b; The else n=c; } Do { If (a==0 n % & amp; & B==0 n % & amp; & N % c==0) {} The else n++; } while (n % a!=0 | | n % b! C=0 | | n %!=0); Printf (" LCM % d ", n); If (a> B) { If (b> C) n=c; If (b} The else { If (a> C) n=c; The else n=a; } Do {
If (a % n==0 & amp; & B % n==0 & amp; & C % n==0) {} The else n -; } while (a % n!=0 | | b % n!=0 | | c % n!=0); Printf (" the greatest common divisor % d ", n); return 0; }
Your judgment while statement is not correct, a==0 n % & amp; & B==0 n % & amp; & N % c==0 means to jump out of the loop, so your code in the while condition must be the opposite of this condition, of course it can write directly the while (1), you can break out of the loop is added when the if the condition is met;