
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find super digit of a number in Python
Suppose we have a number n. We have to find the super digit of this number. The super digit of a single digit number is the digit itself but for multi-digit numbers super digit is the sum of all digits repeatedly until the sum is a single digit number.
So, if the input is like n = 513682, then the output will be 7 because (5+1+3+6+8+2) = 25, (2 + 5) = 7.
To solve this, we will follow these steps −
- s := 0
- while n > 0 or s > 9, do
- if n is same as 0, then
- n := s
- s := 0
- s := s + n mod 10
- n := floor value of n/10
- if n is same as 0, then
- return s
Example
Let us see the following implementation to get better understanding −
def solve(n): s = 0 while(n > 0 or s > 9): if n == 0: n = s s = 0 s += n % 10 n //= 10 return s n = 513682 print(solve(n))
Input
513682
Output
7
- Related Questions & Answers
- C++ program to find first digit in factorial of a number
- C program to find sum of digits of a five digit number
- Program to find sum of digits until it is one digit number in Python
- C++ Program to find the smallest digit in a given number
- C++ program to find sum of digits of a number until sum becomes single digit
- Program to find second largest digit in a string using Python
- 8085 program to find minimum value of digit in the 8 bit number
- Program to find last digit of n’th Fibonnaci Number in C++
- Program to check we can get a digit pair and any number of digit triplets or not in Python
- Find the frequency of a digit in a number using C++.
- Program to Find Out the Occurrence of a Digit from a Given Range in Python
- Python program to find better divisor of a number
- Python program to find factorial of a large number
- C program to find frequency of each digit in a string
- C++ Program to find out the super vertices in a graph
Advertisements