-1
I am doing a program in C that asks for the value of n and two positive integers i and j. With these values I have to calculate n natural numbers that are multiples of i or j and or both. But my code for some reason the program crashes after reading the values, does not calculate any multiple and closes.
int n, i, j, contador, multiplosI, multiplosJ;
printf("Digite o valor de N : ");
scanf("%d",&n);
printf("Digite o valor de I e J : ");
scanf("%d %d",&i,&j);
multiplosI = 0;
multiplosJ = 0;
for (int contador = 0; contador < n; contador ++){
if (i % contador == 0 && j % contador == 0){
multiplosI = contador;
printf("Multiplos de I e J : %d \n",multiplosI);
} else if (i % contador == 0){
multiplosI = contador;
printf("Multiplos apenas de I : %d \n",multiplosI);
} else {
multiplosJ = contador;
printf("Multiplos apenas de J : %d \n",multiplosJ);
}
}
Just not able to understand why there are 2 counters in the program.
– Matheus Santos