You need to find n^m where m is the sum of the digits of n.
Step 1:
Find the sum of digits of n.
You could try the following algorithm, either inline or using a function (method):
Let k=n
m=0
do until k<=0
m+=k%10
k/=10
end do
Step 2:
Raise n to the mth power:
result=1
k=m
do until k<=0
result*=n
k--
end do
The answer will be in "result".
But do take care that the result will not overflow. What to do depends on what you have learned.
write a C function which takes natural number nas argument and calculate the sum of the digits raised to the power of the number of digits in n.
1 answer