if (Number & 0x1)
//number is odd
else
//number is even
2006-08-19 02:56:30
·
answer #1
·
answered by justme 7
·
0⤊
0⤋
ok.. both your previous posters got the logic right, but the syntax wrong
for a bitwise and operation use a single &
&& is used for logical anding
2006-08-19 00:03:16
·
answer #2
·
answered by Neil 5
·
1⤊
0⤋
every odd number (in binary) has 1 on the end ie 10001 is odd.
so just do if (mynum && 1 == 1) odd
(mynum && 1 == 0) even
AND 1 will put all flags to zero except last one
2006-08-18 23:22:41
·
answer #3
·
answered by Bruno 3
·
0⤊
0⤋
When using C as the numeric 0 means boolean false at the same time you can use
if (num && 1) { /*odd here*/ } else {/*even here */}
Loren Soth
2006-08-18 23:27:49
·
answer #4
·
answered by Lord Soth 3
·
0⤊
0⤋
"%x" is used for representing unsigned ints. considering printf is a variadic function it calls for you to explicitly forged values to the properly perfect type like so: printf("%xn", (unsigned int) w); edit: genuinely, considering C makes few assumptions about the host ecosystem, it truly is more beneficial precise to imagine of the bitshift operators as mathematics operators. "a << b" Evaluates to "a" prolonged via "2 raised to the b'th ability" "a >> b" Evaluates to the quotient of "a" divided via "2 raised to the b'th ability"
2016-11-05 03:55:22
·
answer #5
·
answered by treiber 4
·
0⤊
0⤋
main()
{
int x;
scanf("%d",&x);
if((x&1)==1)
printf("The number is odd");
else
printf("The Number is even");
}
2006-08-19 00:25:36
·
answer #6
·
answered by venkatesh 2
·
0⤊
0⤋