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

C program to find all possible outcomes of a dice?

2290


what is the difference between class and unio?

2309


What is modeling?

1007


Why do we use c for the speed of light?

1115


Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

1039


What is sizeof return in c?

998


how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....

1752


Explain enumerated types in c language?

999


Is a pointer a kind of array?

1133


Write a program to swap two numbers without using third variable in c?

1082


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1906


How is a null pointer different from a dangling pointer?

980


What are the types of macro formats?

1068


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

1440


What is context in c?

892