0
This is the code I have but it’s not returning anything. what will be wrong?
#include <stdio.h>
#define nao 0
#define ok 1
int main(){
int x,y,contador1=1, contador2=1,maior,menor, mmc,estado=nao;
scanf("%d %d",&x,&y);
if (x<y){
maior=y;
menor =x;
}
else{
maior=x;
menor=y;
}
if(x>0 && y>0){
while(estado==nao){
while (contador1<=10){
if (menor*contador1==maior*contador2){
estado=ok;
mmc=menor*contador1;
}
else{
contador1++;
}
}
contador2++;
}
}
printf("%d\n",mmc);
return 0;
}
thank you!
What happens if
contador1
become greater than 10 andestado
is still equal tonao
?– Woss
Counter1 doesn’t get bigger than 10 because the while only goes up to 10
– user227365
You can reach up to 11 in your code. If it is equal to 10 still enters the loop and is incremented by 11. Take a table test to better understand the code you wrote.
– Woss
but my question is why the code does not return anything.
– user227365
As soon as you can answer what happens in your code when
contador1
is equal to 11 andestado
is equal tonao
You’ll understand why you don’t return anything. If you don’t understand this situation well, it means you didn’t understand 100% of the code itself, so I suggested doing the table test. You can read more about at What is a Table Test? How to Apply It?.– Woss
@user227365 with what values of x and y have you tested? Your program comes to end by entering these values?
– Eduardo Bissi