Sum of digits of a given number to a given power | CPP program to illustrate the given problem ; Function to calculate sum ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculate ( int n , int power ) { int sum = 0 ; int bp = ( int ) pow ( n , power ) ; while ( bp != 0 ) { int d = bp % 10 ; sum += d ; bp /= 10 ; } return sum ; } int main ( ) { int n = 5 ; int power = 4 ; cout << calculate ( n , power ) ; }