Pregunta de entrevista de Ubisoft

How to check if a number is even or odd without using % or / ?

Respuestas de entrevistas

Anónimo

15 de jul de 2017

perform bitwise AND of given number with 1 and check the last bit if it is zero then number is even and if it is 1 then number is odd

4

Anónimo

21 de may de 2019

int num; cout > num; if ((1 & num) == 1) { cout << "Odd \n"; } else { cout << "Even \n"; }

1

Anónimo

11 de ene de 2019

How if we subtract 2 from given number while x>0. set flag=1 in while loop if x==0 found and break the while loop. Like this : int main() { int x,flag=0; cin>>x; do { x=x-2; if(x==0) { flag=1; break; } }while(x>0); if(flag==1) { cout<<"Even"; } else {cout<<"ODD";} return 0; }

Anónimo

19 de feb de 2019

#include using namespace std; int main() { int n; cout>n; bool flag=false; //lets do the logic //1.even/odd logic for(int i=2;in) { break;//break the loop for time complexity } } } if(flag) { cout<<"It is even number"<