Ubisoft Interview Question: How to check if a number is e... | Glassdoor.co.in

## Interview Question

Junior Programmer Interview(Student Candidate) Pune

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

/ ?

2

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

Interview Candidate on 14-Jul-2017
0

How if we subtract 2 from given number while x&gt;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&gt;&gt;x;
do
{
x=x-2;
if(x==0)
{
flag=1;
break;
}
}while(x&gt;0);
if(flag==1)
{
cout&lt;&lt;"Even";
}
else
{cout&lt;&lt;"ODD";}
return 0;
}

Check this out : on 10-Jan-2019
0

#include
using namespace std;
int main()
{
int n;
cout&gt;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&lt;&lt;"It is even number"&lt;

Dheeraj Mandal on 19-Feb-2019
0

int num;
cout &gt; num;

if ((1 &amp; num) == 1) {
cout &lt;&lt; "Odd \n";
}
else {
cout &lt;&lt; "Even \n";
}

Anonymous on 21-May-2019