Find the player who wins the game of placing alternate + and | C # program for the above approach ; Function to check which player wins the game ; Stores the difference between + ve and - ve array elements ; Traverse the array ; Update diff ; Checks if diff is even ; Driver Code ; Given Input ; Function call to check which player wins the game
using System ; class GFG { static void checkWinner ( int [ ] arr , int N ) { int diff = 0 ; for ( int i = 0 ; i < N ; i ++ ) { diff -= arr [ i ] ; } if ( diff % 2 == 0 ) { Console . Write ( " A " ) ; } else { Console . Write ( " B " ) ; } } public static void Main ( ) { int [ ] arr = { 1 , 2 } ; int N = arr . Length ; checkWinner ( arr , N ) ; } }