![]() |
Harshad Numbers can be divided by the sum of its digits. They are also called Niven Numbers. For instance, 18 is a Harshad Number as it can be divided by 9, the sum of its digits (8+1=9). In this article, we will discuss various approaches to determine whether the given number is a Harshad Number in Python. Example: Input: 18 Output: 18 is a Harshad Number Input: 15 Output: 15 is not a Harshad Number Python Program to Check If a Number is a Harshad NumberBelow are some of the approaches by which we can check if a number is a Harshad Number using Python:
Using LoopIn this example, the
Output Yes No Using StringIn this example, we are using str() function to check if a number is a Harshad Number or not.
Output Yes No |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |