Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

To find whether a number is even or odd without using any
conditional operator??

Answer Posted / yogeshkumar

Check given number is even or odd without using modulo operator.
for this we use & operator.
if any number is odd it must have right most bit 1.
example:
int i=5;
binary form i= 0101
now use & operator
int j=i&1;[0101&1]//
here j have 0001;

public class EvenandOddNumber {
public static void main(String[] args) {
int i=5;
int j=i&1;
if(j>0){
System.out.println("odd");
}
else {
System.out.println("even");
}
}
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is wrong with this declaration?

1110


What is the scope of static variable in c?

1026


Is linux written in c?

1041


How will you write a code for accessing the length of an array without assigning it to another variable?

1058


Why clrscr is used after variable declaration?

1696


What does void main return?

1129


Linked lists -- can you tell me how to check whether a linked list is circular?

1095


What are the types of variables in c?

1024


Why is a semicolon (;) put at the end of every program statement?

1076


How many types of operator or there in c?

1100


What are valid operations on pointers?

1203


What are global variables and explain how do you declare them?

1108


What is the difference between functions getch() and getche()?

1098


What is the difference between declaring a variable and defining a variable?

1283


What is New modifiers?

1132