Python Program to Check Harshad Number
In mathematics, a number is said to be Harshad number if it is divisible by the sum of its digits.
Harshad number examples: 153, 156, 24 etc.
153 is Harshad number becuase it is divisible by 1+5+3=9 i.e. 153/(1+5+3) = 153/9 = 17.
This program checks whether a given number by user is Harshad number or not.
Python Source Code: Harshad Number
# Harshad Number
# Reading number
number = int(input('Enter number: '))
# Making copy of number for later use
copy = number
# Finding sum of digit
digit_sum = 0
while number:
digit_sum += number%10
number //= 10
# Checking divisibility & making decision
if copy%digit_sum == 0:
print('%d is Harshad Number' % (copy))
else:
print('%d is Not Harshad Number' % (copy))
Harshad Check Output
Run 1: ----------------- Enter number: 153 153 is Harshad Number Run 2: ----------------- Enter number: 154 154 is Not Harshad Number