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 infinite loop?

1131


how do you execute a c program in unix.

1157


What are the types of operators in c?

1100


What is a nested formula?

1235


How do c compilers work?

1199


What is modifier & how many types of modifiers available in c?

1072


Write a program of advanced Fibonacci series.

1203


What is the use of clrscr?

1156


Explain how do you print only part of a string?

1278


Why are algorithms important in c program?

1172


Can you please explain the difference between strcpy() and memcpy() function?

1120


Why isn't any of this standardized in c? Any real program has to do some of these things.

1264


What are the 4 types of programming language?

1187


a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

1128


Is there any data type in c with variable size?

1145