1. ## Logical expressions

I have to write logical expressons in C for the following..

x is a negative integer which is greater than -2000
x is a positive integer which is not divisble by 10
x is an even number greater than 1000
m is a legitimate month number
The values in a, b and c are equal
The values in a, b and c are not all equal

I'm just wondering if i'm on the right track with these:

(x<0) && (x>-2000)
(x>0) && (x!%10)
(x%2==0) && (x>1000)
1 < m <12
a==b==c
! (a==b==c)

2. x!%10 makes no sense. 1 < m < 12 makes sense, but not the kind of sense you want. Same with a==b==c. Remember that <, >, ==, and all the rest will always and forever evaluate to either 0 or 1.

3. 1 is correct.
3 is correct.
4 is incorrect (will not give you what you want).
5 is correct, although may be bad practice since it may not give you what you want every time, but works in this scenario. 6 is the same.

4. Cheers for the replies guys. I've had another go, hopefully you might be able to have a look at these too:

(x>0) && ((x%10)!==0)

(m>1) && (m<12)

(a==b) && (b==c)

(a==b) || (b==c) || (a==c)

5. The first one still has a syntax error
(x>0) && ((x&#37;10)!==0)
But perhaps it was a typo.

The second one is a logical error. You're saying if m is BIGGER than 1 and m is LESS than 12. Last time I checked, 1 and 12 are valid months.

3rd is good.

I'm not sure if the 4th is what you want. You're testing equality instead of inequality.

6. There ya go.

The first one could have been (x>0) && !(x&#37;10) too.

7. Cheers for that again lads. I see where i went wrong

Should have wrote != for 1st one,
(m>=1) && (m<=12) for 2nd one.

i'm hoping i'm right here for the last one

(a!=b) || (b!=c) || (a!=c)

8. I'm not sure how the professor expected you to interpret "The values in a, b and c are not all equal"
You solved it one way.

Or he could be wanting
Code:
`!((a==b) && (b==c))`
... meaning, some could be equal, but not all at the same time. Basically the previous problem negated.