int main()
{
int num;
int num2;
printf("Enter two numbers\n");
scanf("%i\n",&num);
scanf("%i\n",&num2);
if (num % num2 == 0){
printf("%i is evenly divided by %i",num,num2);
}
else {
printf("%i is not evenly divided by %i", num, num2);
}
return 0;
}
When I run the above code in the terminal, this is what happens
Enter two numbers
3
4
dsfa
3 is not evenly divided by 4
I entered two numbers, but then nothing happens until I enter some form of text (this is what is random "dsfa") and then the program will return with the correct operator printf. It should be text, I canβt just press the enter button (where do the spaces come from). Why does this program not return what I intend immediately after the user enters two numbers?
source
share