- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to find the minimum and maximum number, using binary operations.
Examples
For example, x = 12, y = 15 => Maximum number is 15.
For example, x = 13, y = 17 => Minimum number is 13.
Approach to solve this problem
Step 1 − Define method, findMax and findMin, that accept two integer x and y.
Step 2 − Return integer according to defined method.
Example
package main import "fmt" func FindMax(x, y int){ fmt.Printf("Maximum element in %d, and %d is: %d\n", x, y, x - ((x - y) & ((x - y) >> 31))) } func FindMin(x, y int) { fmt.Printf("Minimum element in %d, and %d is: %d\n", x, y, y + ((x - y) & ((x - y) >> 31))) } func main(){ FindMax(12, 15) FindMin(13, 17) FindMax(1, 0) }
Output
Maximum element in 12, and 15 is: 15 Minimum element in 13, and 17 is: 13 Maximum element in 1, and 0 is: 1
- Related Articles
- Minimum number of operations required to sum to binary string S using C++.
- Program to find minimum possible maximum value after k operations in python
- Program to find minimum operations to make the array increasing using Python
- Program to find minimum operations to make array equal using Python
- Golang program to get maximum and minimum from a slice
- Program to find minimum number of operations to make string sorted in Python
- C++ program to find minimum how many operations needed to make number 0
- C++ Program to find out the minimum number of operations required to defeat an enemy
- Program to find minimum number of operations required to make one number to another in Python
- Program to find equal sum arrays with minimum number of operations in Python
- Golang program to find minimum spanning tree using dijkstra Algorithm
- Find the Number of Subarrays whose Minimum and Maximum are Same using C++
- C++ Program to Find the maximum subarray sum using Binary Search approach
- Program to find minimum swaps to arrange a binary grid using Python
- Program to find minimum number of operations required to make lists strictly Increasing in python

Advertisements