+ 7
How output is 13579 ????
please describe it https://code.sololearn.com/c475xLs41fMN/?ref=app
4 ответов
+ 8
here if(i&1) is working as if the binary form of i ends with 1 the if condn satisfies and prints the value of i.
For eg: i is 2 then binary form is 10 so it doesn't satisfies the condn & it will not be printed whereas if i = 3 binary form is 11 so the last bit ends with 1 so it will be printed ...series continues !!
+ 11
for(int i=0;i<10; i++)
{
if(i&1)
cout<<i;
}
in this every bit of both opersnds are multiply
0&1=0*1=0 and 0=false
1&1=1*1=1 and 1=true so odd number
2&1=>10&01=>10=>00=0=>false
01
3&1=> 11&01=>11=>01=>true=odd
01
and so on
+ 6
all odds is the output.
"&" is "logical and" similar to the gates you might have studied in electronics.
if u "and" some odd number with 1 it gives 1 as an output while zero for even.
+ 5
thanks Raj & Steasy