Find the Missing Number | C # program to implement the above approach ; Function to find missing number ; Driver code
using System ; class GFG { static int getMissingNo ( int [ ] a , int n ) { int n_elements_sum = ( n * ( n + 1 ) / 2 ) ; int sum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) sum = sum + a [ i ] ; return ( n_elements_sum - sum ) ; } public static void Main ( ) { int [ ] a = { 1 , 2 , 4 , 5 , 6 } ; int miss = getMissingNo ( a , 5 ) ; Console . Write ( miss ) ; } }