Computer Science, asked by Anonymous, 9 months ago

Write a python program using bitwise operators to find maximum between four numbers. i want coding of python program not in other languages like C++, java, etc​

Answers

Answered by rushilansari
0

Answer:

# Python program to find maximum of 4 numbers  

# without using conditional and bitwise  

# operators.  

def maxOfFour(w, x, y, z):  

   a = [0] * 2

   a[0] = w  

   a[1] = x  

     

   # b is 0 if w is less than or equal  

   # to x, else it is non-zero.  

   b = bool(a[0] - a[1] + abs(a[0] - a[1]))  

   if b:  

       b = 1

   else:  

       b = 0

 

   # After below operation, a[0] is maximum  

   # of w and x.  

   a[0], a[1 - b] = a[1 - b], a[0]  

     

   # After below three steps, a[0] is maximum  

   # of w, x and y.  

   a[1] = y  

   b = bool(a[0] - a[1] + abs(a[0] - a[1]))  

   if b:  

       b = 1

   else:  

       b = 0

   a[0], a[1 - b] = a[1 - b], a[0]  

     

   # After below three steps, a[0] is maximum  

   # of w, x, y and z.  

   a[1] = z  

   b = bool(a[0] - a[1] + abs(a[0] - a[1]))  

   if b:  

       b = 1

   else:  

       b = 0

   a[0], a[1 - b] = a[1 - b], a[0]  

     

   return a[0]  

 

# Driver code  

w = 12

x = 15

y = 18

z = 17

print("Maximum of four : ", maxOfFour(w, x, y, z))

Similar questions