Given a number N in decimal base, the task is to find the sum of digits of the number in any base B.
Input: N = 100, B = 8
(100)8 = 144
Sum(144) = 1 + 4 + 4 = 9
Input: N = 50, B = 2
(50)2 = 110010
Sum(110010) = 1 + 1 + 0 + 0 + 1 + 0 = 3
Approach: Find unit digit by performing modulo operation on number N by base B and updating the number again by N = N / B and update sum by adding the unit digit at each step.
Below is the implementation of above approach
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Given a number N in decimal base, find number of its digits in any base (base b)
- Find the Nth digit from right in base B of the given number in Decimal base
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Find the total count of numbers up to N digits in a given base B
- Check if the number is even or odd whose digits and base (radix) is given
- Check if a given number can be represented in given a no. of digits in any base
- Add two integers of different base and represent sum in smaller base of the two
- Convert from any base to decimal and vice versa
- Convert all substrings of length 'k' from base 'b' to decimal
- Find most significant bit of a number X in base Y
- Find the length of factorial of a number in any given base
- Find the Largest N digit perfect square number in Base B
- All possible numbers of N digits and base B without leading zeros
- Program to find the last digit of X in base Y
- Check if a number is in given base or not
- Complement of a number with any base b
- Pandigital number in a given base
- Check if a N base number is Even or Odd
- Largest N digit number in Base B
- Number System and Base Conversions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.