0
In this exercise it is to type two numbers and print on the screen themselves, and the integers between them. However, if I type for example 10 and 20, the last number that appears is 19 instead of 20; and if I type 20 and 10, the last number appears 11.
My mistake is not in if
For what I have tested, I may be wrong.
NOTE: I need to use while.
#include <stdio.h>
#include <stdlib.h>
int n1, n2;
main()
{
printf("Para saber os inteiros entre dois numeros siga os passos abaixo: \n");
printf("Digite o primeiro numero: ");
scanf("%d", &n1);
printf("Digite o segundo numero: ");
scanf("%d", &n2);
system("cls");
if((n1 == n2)||(n2 == n1)){
printf("NUMEROS IGUAIS!\n");
}
while((n1 < n2)||(n1 > n2))
{
if(n1 < n2){
printf("%d\n", n1);
n1 = n1 + 1;
}else if(n1 > n2){
printf("%d\n", n1);
n1 = n1 - 1;
}
}
return 0;
}
Need to better define the problem if it is to print the numbers between them is to print from 11 to 19.
– Maniero
I edited the question, I think it’s clearer now.
– Luciano Balestrin Correa