Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

What algorithm calculates the sum of digits in a number. Say you want to sum the digits in 4^10, what algorithm could you use?

Computer Science
See more answers at
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly


Get your free account and access expert answers to this and thousands of other questions

You could use something like this : Lets say you have a number in num and want to add its digits and store in sum . for .e.g. num=12345,sum=0; 1. while num is greater than 0 do following else goto step 5 2. calculate sum as : sum=sum+num mod 10; 3. modify num num=num div 10; 4. goto step 1 5. print sum as result
I think the asker was interested in finding the answer when there is only an expression for the original number like 4^10 rather than 23897
rivermaker, perhaps - however it would be easy enough to write some code to take in the string "4^10" and then turn that into a real number, wouldn't it? Then the above algorithm would apply, yes? Also worth noting that the above algorithm will only work for whole numbers. If you have decimal points involved, I believe things get hairy.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

i agree with farmdawgnation . i thought asker meant to find sum of digits of any number in general. sorry for misunderstanding that . but offcourse one anconvert that into a real number. And secondly, yes this algo will not work correctly for floating numbers.

Not the answer you are looking for?

Search for more explanations.

Ask your own question