Sum of digits of a given number to a given power | C # program to find sum of digits of a given number to a given power ; Function to calculate sum ; Driver Code
using System ; public class base_power { static int calculate ( int n , int power ) { int sum = 0 ; int bp = ( int ) Math . Pow ( n , power ) ; while ( bp != 0 ) { int d = bp % 10 ; sum += d ; bp /= 10 ; } return sum ; } public static void Main ( ) { int n = 5 ; int power = 4 ; Console . WriteLine ( calculate ( n , power ) ) ; } }