Explanation
In this program, we need to determine whether given is Harshad or not.
Harshad number
A number is said to be the Harshad number if it is divisible by the sum of its digit.
For example, if number is 156, then sum of its digit will be 1 + 5 + 6 = 12. Since 156 is divisible by 12. So, 156 is a Harshad number.
Some of the other examples of Harshad number are 8, 54, 120, etc.
To find whether the given number is a Harshad number or not, calculate the sum of the digit of the number then, check whether the given number is divisible by the sum of its digit. If yes, then given number is a Harshad number.
Algorithm
- Define and initialize variable num.
- Make a copy of the num by storing the value of num in variable n.
- If num is greater than 0, then calculate the remainder by dividing num with 10.
- Add rem to a variable sum.
- Divide num by 10.
- Repeat the steps from 3 to 5, to calculate the sum of all digits present in a given number.
- If n (copy of original number) is divisible by the sum, then given number is a Harshad number. Else, given number is not a Harshad number.
A number is said to be the Harshad number if it is divisible by the sum of its digit.
Input:
num = 156
Output:
Python
Output:
C
Output:
JAVA
Output:
C#
Output:
PHP
Output: