Check if the number is balanced | C # program to check if a number is Balanced or not ; Function to check whether N is Balanced Number or not ; Calculating the Leftsum and rightSum simultaneously ; Typecasting each character to integer and adding the digit to respective sums ; Driver code ; Function call
using System ; class GFG { static void BalancedNumber ( string s ) { int Leftsum = 0 ; int Rightsum = 0 ; for ( int i = 0 ; i < s . Length / 2 ; i ++ ) { Leftsum += ( int ) ( Char . GetNumericValue ( s [ i ] ) - Char . GetNumericValue ( '0' ) ) ; Rightsum += ( int ) ( Char . GetNumericValue ( s [ s . Length - 1 - i ] ) - Char . GetNumericValue ( '0' ) ) ; } if ( Leftsum == Rightsum ) Console . WriteLine ( " Balanced " ) ; else Console . WriteLine ( " Not ▁ Balanced " ) ; } static void Main ( ) { string s = "12321" ; BalancedNumber ( s ) ; } }