JavaScript Pronic Number Program

Beginner
5 min read
Updated: Oct 2026
3 programs
Live preview

What Is a Pronic Number?

A pronic number (also called oblong or rectangular) is the product of two consecutive integers:

Remember
n = k × (k + 1)   for some integer k ≥ 0

Examples: 0, 2, 6, 12, 20, 30, 42, ...
12 = 3 × 4
20 = 4 × 5
nFormPronic?
123 × 4Yes
00 × 1Yes
93 × 3 (not consecutive)No
1—No

How to Check a Pronic Number in JavaScript

Four clear steps — then reuse the helper to list pronic numbers in a range.

  1. If n < 0, return false (this tutorial uses non-negative n).
  2. Start k = 0.
  3. While k × (k + 1) ≤ n, if the product equals n, return true.
  4. If the product passes n with no match, return false.
MethodIdeaTimeBest for
Loop on kTry products until > nO(√n)Single check (default)
Range scanCall isPronic for each valueO(N√N)Listing pronic 0..N
GenerateCompute k × (k + 1) directlyO(kMax)Building the sequence

Pseudocode

Pseudocode
function IsPronic(n):
    if n < 0: return false

    k = 0
    while k * (k + 1) <= n:
        if k * (k + 1) == n:
            return true
        k = k + 1

    return false

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
Definitionn = k × (k + 1) for integer k ≥ 0
Also calledOblong / rectangular numbers
0Pronic (0 × 1)
1 and 9Not pronic
EvennessFor k ≥ 1, product is always even
Classic checks12 yes; 20 yes; 9 no

Live Preview

Enter an integer to try consecutive products until they pass n.

Whole numbers only. Tap a chip or type a value.

Result
n = 12
Try k = 0, 1, 2, 3, ...
3 × 4 = 12
12 is pronic

JavaScript Programs

Start with a reusable isPronic helper, list matches in a range, then generate the sequence by multiplying. Each example has a Try it Yourself editor.

Example 1 — isPronic Check

Return true when some consecutive product equals n.

JavaScript
function isPronic(n) {
  if (n < 0) {
    return false;
  }

  for (let k = 0; k * (k + 1) <= n; k++) {
    if (k * (k + 1) === n) {
      return true;
    }
  }

  return false;
}

const number = 12;
if (isPronic(number)) {
  console.log(number + " is pronic");
} else {
  console.log(number + " is not pronic");
}
Try It Yourself

How It Works

  1. Negative values are rejected first.
  2. The loop grows k while k × (k + 1) stays ≤ n.
  3. Equality means two consecutive factors were found.
  4. If the product jumps past n, no match exists.
  5. For 12, k = 3 gives 3 × 4, so the answer is true.

Example 2 — Pronic Numbers in a Range

Reuse isPronic to print every pronic value from 0 to 30.

JavaScript
function isPronic(n) {
  if (n < 0) {
    return false;
  }

  for (let k = 0; k * (k + 1) <= n; k++) {
    if (k * (k + 1) === n) {
      return true;
    }
  }

  return false;
}

const start = 0;
const end = 30;

console.log("Pronic numbers from " + start + " to " + end + ":");
let line = "";
for (let i = start; i <= end; i++) {
  if (isPronic(i)) {
    line += i + " ";
  }
}
console.log(line.trim());
Try It Yourself

How It Works

  1. Same isPronic helper keeps the rule in one place.
  2. The outer loop visits every integer from start to end.
  3. Only values that pass the helper are collected.
  4. 0 is included because 0 × 1 = 0.
  5. For larger ranges, generate products directly with k++ instead of scanning every i.

Example 3 — Generate Sequence

Build pronic numbers directly by computing k × (k + 1).

JavaScript
const kMax = 6;

console.log("Pronic numbers for k = 0 to " + kMax + ":");
for (let k = 0; k <= kMax; k++) {
  const value = k * (k + 1);
  console.log(k + " * " + (k + 1) + " = " + value);
}
Try It Yourself

How It Works

  1. kMax is the largest starting factor you want to print.
  2. Each step multiplies consecutive integers k and k + 1.
  3. No search is needed — every product is pronic by definition.
  4. Change kMax in the Try it Yourself editor to print a longer list.
  5. This is the fastest way to list many pronic numbers in order.

Edge Cases & Pitfalls

Check these before calling the solution done.

0

Zero is pronic

0 × 1 = 0 — do not reject zero by habit.

Squares

Not the same

9 = 3 × 3 is a square, not consecutive factors.

Precision

Safe integers

For very large n, stay within Number.MAX_SAFE_INTEGER so k * (k + 1) stays exact.

Negatives

Out of scope

This tutorial treats only non-negative inputs as candidates.

Time and Space Complexity

ProgramTimeExtra space
isPronic (loop on k)O(√n)O(1)
Pronic in range 0..NO(N√N)O(1)
Generate sequenceO(kMax)O(1)

Because k × (k + 1) ≈ k², the check loop stops near √n. Generating products with k++ is faster for long ranges.

Key Takeaways

  • Definition: n = k × (k + 1) for some integer k ≥ 0.
  • Check: try products until they pass n.
  • Facts: 0 is pronic; squares like 9 are not automatically pronic.
  • Test set: 12 → yes; 20 → yes; 9 → no; 1 → no.

One line: if some consecutive pair multiplies to n, n is pronic.

Frequently Asked Questions

A pronic number equals k × (k + 1) for some integer k ≥ 0. Examples: 0, 2, 6, 12, 20, 30.
Yes. 0 = 0 × 1.
No. No integer k satisfies k × (k + 1) = 1.
Among any two consecutive integers, one is even, so their product is even.
A loop that tries k while k × (k + 1) ≤ n runs in O(√n) time and O(1) extra space.
Use the Try it Yourself links under each code sample — they open an in-browser editor with the same logic so you can edit the input and Run.

Next: Smith Number

Compare digit sums with prime-factor digit sums.

Smith number tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful