Compute average of two numbers without overflow | C ++ code to compute average of two numbers ; Function to compute average of two numbers ; Driver code ; Assigning maximum integer value ; Average of two equal numbers is the same number ; Function to get the average of 2 numbers
#include <bits/stdc++.h> NEW_LINE using namespace std ; int compute_average ( int a , int b ) { return ( a + b ) / 2 ; } int main ( ) { int a = INT_MAX , b = INT_MAX ; cout << " Actual ▁ average ▁ : ▁ " << INT_MAX << endl ; cout << " Computed ▁ average ▁ : ▁ " << compute_average ( a , b ) ; return 0 ; }