Form a number using corner digits of powers | C # program to find number formed by corner digits of powers . ; Find next power by multiplying N with current power ; Store digits of Power one by one . ; Calculate carry . ; Store carry in Power array . ; Prints number formed by corner digits of powers of N . ; Storing N raised to power 0 ; Initializing empty result ; One by one compute next powers and add their corner digits . ; Call Function that store power in Power array . ; Store unit and last digits of power in res . ; Driver Code
using System ; using System . Collections . Generic ; using System . Linq ; using System . Collections ; class GFG { static void nextPower ( int N , ref List < int > power ) { int carry = 0 ; for ( int i = 0 ; i < power . Count ; i ++ ) { int prod = ( power [ i ] * N ) + carry ; power [ i ] = prod % 10 ; carry = prod / 10 ; } while ( carry >= 1 ) { power . Add ( carry % 10 ) ; carry = carry / 10 ; } } static void printPowerNumber ( int X , int N ) { List < int > power = new List < int > ( ) ; power . Add ( 1 ) ; List < int > res = new List < int > ( ) ; for ( int i = 1 ; i <= X ; i ++ ) { nextPower ( N , ref power ) ; res . Add ( power . Last ( ) ) ; res . Add ( power . First ( ) ) ; } for ( int i = 0 ; i < res . Count ; i ++ ) Console . Write ( res [ i ] ) ; } public static void Main ( ) { int N = 19 , X = 4 ; printPowerNumber ( X , N ) ; } }