Asked by Alice
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.
Answers
Answered by
MathMate
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.
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.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.