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;

CodePudding user response:

The
reference 3 floor datoulaile123 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;

Meet the need of jump out when n is the number?

CodePudding user response:

reference 4 floor SYoooooh response:
Quote: reference datoulaile123 reply: 3/f
 # 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;

Meet the need of jump out when n is the number?

While in the condition of parameter is 0 continue to cycle, 0 stop cycle, if you had written & amp; & , do you think of n % a!=0 to satisfy the conditions out of circulation, in fact you want to do is to satisfy all three are divisible to jump out of the loop, you can be in circulation n++; Behind add a Boolean value of variables, and then in your code n % a!=0 & amp; & N % b!=0 & amp; & N % c!=0 assigned to the variable to see if it is true or false, you will find that n as long as be divided exactly by a number, he is the false (in your terms of while is out of the loop)

CodePudding user response:

reference 5 floor datoulaile123 reply:
Quote: refer to 4th floor SYoooooh response:

Quote: refer to the third floor datoulaile123 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 {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related