0
I’ve developed an algorithm that should display the largest multiple between num1 <= num2
. I used as example 7 and 50 and worked correctly, displaying the value 49, but when sending for evaluation there is an inconsistency that I do not recognize.
#include <stdio.h>
int main() {
int num1, num2, i, temp, resultado;
scanf("%i", & num1);
scanf("%i", & num2);
if (num1 > num2) {
temp = num1;
num1 = num2;
num2 = temp;
}
for (i = num1; i <= num2; i++) {
if (num1 % i == 0) {
resultado = num1 * i;
}
}
if (resultado <= num2) {
printf("%i\n", resultado);
} else {
printf("sem multiplos menores que %i", num2);
}
return 0;
}
"but when sending for evaluation there is an inconsistency that I am not recognizing" as well as inconsistency, which means?
– Ricardo Pontual
Hello, I’ll show you the link to the question, http://thehuxley.com/problem/36. The tips are: Are you really finding the biggest one? Isn’t there another even bigger number? .
– betafico123
need only explain what you mean by inconsistency
– Ricardo Pontual
The site states that I am not finding the largest multiple nor including the num2
– betafico123
@Mauroalmeida The example given on the site with the input and output are these, http://thehuxley.com/problem/36
– betafico123
On the understanding of the question: in my opinion the question does not ask you to invert the numbers if num2 < num1, in this case the answer would be "without multiples smaller than N". In terms of logic: as it is to find the largest multiple I would start the test on N and would decrement until finding the first multiple, or eventually get to M, in a while loop.
– anonimo