# Thread: Logic evaluation of an expression

1. ## Logic evaluation of an expression

I am having a little problem with a logic evaluation of a simple expression,
perhaps I need a nudge in the right direction:
Given an assignment x = 9,
I am trying to evaluate the following - (x%2==0) and (x%3==0).

The output gives
0 and 1 respectively
as in
(x ==0) is evaluated as : 0
and
(x ==0) is evaluated as : 1
Looks strange to me, probably needs some explanation if correct

Thanks!

Actual Code:
Code:
```/*Q8.4.C:  Evaluating an  operand */
#include <stdio.h>

main()
{
int x;
x = 9;
printf("Given x = 9, \n");
printf("(x%2==0) is evaluated as :  %i \n ", (x%2==0) );
printf("and \n");
printf("(x%3==0) is evaluated as :  %i \n ", (x%3==0) );
return 0;
}``` 2. What is the result of: 9%2 3. Originally Posted by jaymax Given an assignment x = 9,
I am trying to evaluate the following - (x%2==0) and (x%3==0).

The output gives

as in
and

What do you expect? What do you even want? Of course 9%2 is 1, of course 9%3 is 0. What else would the result be? 4. Thanks! Matticus and Yanin, your replies made it clear: I had been stuck thinking of "(x%2==0) and (x%3==0)" in terms of some 'unknown to me' format specifier and not of the % being the modulus or remainder operator.
Thanks again. 5. Originally Posted by jaymax Thanks! Matticus and Yanin, your replies made it clear: I had been stuck thinking of "(x%2==0) and (x%3==0)" in terms of some 'unknown to me' format specifier and not of the % being the modulus or remainder operator.
Thanks again.
Keep in mind, format specifiers only apply to printf and scanf families of functions, and then only to the format string itself, not to other parameters. Technically, there are other functions that use similar format specifiers, but those are the two common ones that exist in all C implementations. Popular pages Recent additions 