How output is 13579 ???? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 7

How output is 13579 ????

please describe it https://code.sololearn.com/c475xLs41fMN/?ref=app

21st Dec 2017, 3:16 PM
Ramshek Rana
Ramshek Rana - avatar
4 Antworten
+ 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 !!
21st Dec 2017, 3:36 PM
Rishabh
Rishabh - avatar
+ 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
21st Dec 2017, 3:42 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 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.
21st Dec 2017, 5:54 PM
Infinity
Infinity - avatar
+ 5
thanks Raj & Steasy
21st Dec 2017, 4:09 PM
Ramshek Rana
Ramshek Rana - avatar