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
using System ; public class GFG { static int compute_average ( int a , int b ) { return ( a + b ) / 2 ; } static public void Main ( ) { int a = int . MaxValue ; int b = int . MaxValue ; Console . WriteLine ( " Actual ▁ average ▁ : ▁ " + int . MaxValue ) ; Console . WriteLine ( " Computed ▁ average ▁ : ▁ " + compute_average ( a , b ) ) ; } }