![]() |
Pronic numbers are also called oblong numbers or rectangular numbers. They are produced by multiplying two successive integers. Mathematically, it can be written as n * (n + 1), where n is a positive integer. For instance, 6 is a pronic number because it equals 2 * (2 + 1). Similarly, when you multiply 3 by 4 it equals; hence,12 is another pronic number as it is equal to 3 * (3 + 1) Example: Input: n1 = 1, n2 = 100 Output: 2, 6, 12, 20, 30, 42, 56, 72, 90 Python Program to Print All Pronic Numbers Between 1 and 100Below are some of the ways by which we can print all pronic numbers between 1 and 100 in Python:
Approach 1: Using a LoopIn this approach, a single loop from one to the given limit(n) iterates over simple values. It examines all i and checks if their products with i+1 fall within the specified limits. If so then i*(i+1) makes a pronic number which is displayed immediately.
Output Pronic Numbers Between 1 and 100: 2 6 12 20 30 42 56 72 90 Approach 2: Using List ComprehensionList comprehension offers an elegant way of generating list of pronic numbers. As such it goes through range of numbers computing product between each number and its next consecutive integer and stores them on list .
Output Pronic Numbers Between 1 and 100: 2 6 12 20 30 42 56 72 90 110 |
Reffered: https://www.geeksforgeeks.org
Python |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |