What are Harshad Numbers?
For explicit calculations Harshad number or Niven numbers for a given number base represents an integer which is divisible by the sum of its own digit for example 112, the sum of digits of 112 is 4 and 112 is itself divisible by 4 so it comes under the category of a Harshad Number. These numbers in the base are also known by the name n-Harshad numbers. Defining all numbers in the form of positive integer which is also divisible by the sum of its digits in bases n>2. The numbers which are all Harshad numbers are 1, 2, 4 and 6. In order to check if a number is a Harshad number or not we can follow-
- Input number
- Calculate the sum of its digits
- If the number is divisible by the sum of digits, print "Harshad number"
- If the number is not divisible by the sum of its digits, print "not Harshad number
There are many such kinds of numbers with different peculiar properties and one should know at least the popular ones.
BY Best Interview Question ON 17 Oct 2019