Count changes in Led Lights to display digits one by one | C # program to count number of on offs to display digits of a number . ; store the led lights required to display a particular number . ; compute the change in led and keep on adding the change ; Driver code
using System ; class GFG { public static int countOnOff ( string n ) { int [ ] Led = new int [ ] { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 5 } ; int len = n . Length ; int sum = Led [ n [ 0 ] - '0' ] ; for ( int i = 1 ; i < len ; i ++ ) { sum = sum + Math . Abs ( Led [ n [ i ] - '0' ] - Led [ n [ i - 1 ] - '0' ] ) ; } return sum ; } public static void Main ( string [ ] args ) { string n = "082" ; Console . WriteLine ( countOnOff ( n ) ) ; } }