{"id":14287,"date":"2021-10-01T10:30:02","date_gmt":"2021-10-01T05:00:02","guid":{"rendered":"https:\/\/python-programs.com\/?p=14287"},"modified":"2021-11-22T18:33:29","modified_gmt":"2021-11-22T13:03:29","slug":"python-program-to-print-all-harshad-numbers-within-given-range","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-all-harshad-numbers-within-given-range\/","title":{"rendered":"Python Program to Print all Harshad Numbers within Given Range"},"content":{"rendered":"

In this article, we will learn how to print Harshad numbers within a specific range in Python. You will learn what a Harshad number is, how to check whether a given number is a Harshad number, and how to write\u00a0a Python code that outputs all the Harshad numbers within the user-specified range.<\/p>\n

Harshad Number:<\/strong><\/p>\n

If the given number is divisible by the sum of its constituent digits, we can conclude that the given number is a Harshad number.<\/p>\n

Given the lower limit range and upper limit range, the task is to print all the Harshad numbers in the given range.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given upper limit range =11\r\nGiven lower limit range =178<\/pre>\n

Output:<\/strong><\/p>\n

The Harshad numbers in the given range 11 and 178 are:\r\n12 18 20 21 24 27 30 36 40 42 45 48 50 54 60 63 70 72 80 81 84 90 100 102 108 110 111 112 114 117 120 126\r\n 132 133 135 140 144 150 152 153 156 162 171<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given upper limit range =160\r\nGiven lower limit range =378<\/pre>\n

Output:<\/strong><\/p>\n

The Harshad numbers in the given range 160 and 378 are:\r\n162 171 180 190 192 195 198 200 201 204 207 209 210 216 220 222 224 225 228 230 234 240 243 247 252 261\r\n 264 266 270 280 285 288 300 306 308 312 315 320 322 324 330 333 336 342 351 360 364 370 372 375 378<\/pre>\n

Program to Print all Harshad Numbers within Given Range in Python<\/h2>\n

Below are the ways to print all the Harshad numbers in the given range.<\/p>\n