[Practice] Harshad number


Submit solution

Points: 5
Time limit: 0.5s
Memory limit: 2M

Author:
Problem type
Allowed languages
C

Problem Definition

Check if the given number is Harshad's Number using the function isHarshad. This function shall return 1 (if the given number is Harshad), 0 (if not Harshad), and -1 (if the number is <= 0).

Harshad Number

Positive integers that are divisible by the sum of their digits. Consider the number 18. The sum of its digits is 1 + 8 = 9, 18 is divisible by 9.

Test Data

Sample Input 1

-1

Sample Output 1

Number should be greater than 0.

Sample Input 2

23

Sample Output 2

23 is not a Harshad number.

Sample Input 3

21

Sample Output 3

21 is a Harshad number.


Comments

There are no comments at the moment.