and how to get the correct sum
Sir why it is showing sum=0
@rakesh800650
while(n>0)
{
n=n/10;
k++;
}cout<<k;
this first while loop ends when n becomes 0, so now n is 0, so the following loop doesn’t run coz n = 0,
while(n>0)
{
int r=n%10;
sum+=pow(r,k);
n=n/10;
}cout<<sum;
so the solution is that before running the first loop, preserve n in another variable n1
then run second loop on n1 instead of n. sum won’t show 0 then.
Thanks madam for solving the query
1 Like
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.