Can someone please explain what really goes on in this code ?
If I put the AND statement, the message wont show if values are less than 0 or greater than 10 … I think I must use 1 0 logic to work this out right ?
I just need someone to briefly explain it please.
#include<stdio.h>
main(){
puts("enter number");
scanf("%d",num);
if(num<0 || num >10)
puts("yay");
}
How is that IF statement different when AND is put :
#include<stdio.h>
main(){
puts("enter number");
scanf("%d",num);
if(num<0 && num >10)
puts("yay");
}
Thanks !!
This is based on Boolean logic:
Notice how those differ when one side is true and the other is false.
Anyway, in your test:
It’s not possible for a number to both be
< 0and at the same time be> 10. Because of this, you will either evaluatetrue && false(for negative numbers),false && false(for numbers between 0 and 10 inclusive) orfalse && true(for numbers larger then 10). In all those cases, the boolean logic says the answer isfalse.