The Leibniz harmonic triangle is a triangle of fractions. The edges are 1, 1/2, 1/3, 1/4, 1/5, and each fraction equals the sum of the two fractions below it, which is Pascal’s rule turned upside down.
Quick answer: Every entry has 1 on top, so only the bottom number has to be worked out: the denominator in row i, position j (from 0) is (i + 1) × C(i, j), where C is the binomial coefficient from Pascal’s triangle. Build C with c = c × (i − j) / (j + 1), print 1 or 1/den, and move on.
This program is part of the Series Patterns collection.
Table of contents8 sections
Leibniz Harmonic Triangle output
Output (n = 5):
1 1/2 1/2 1/3 1/6 1/3 1/4 1/12 1/12 1/4 1/5 1/20 1/30 1/20 1/5

How the leibniz harmonic triangle works
The German mathematician Gottfried Leibniz used this triangle in the 1670s to add up series of fractions. Its link with Pascal’s triangle makes the code short: take row i of Pascal’s triangle, multiply every number by i + 1, and put each result under a 1. The program creates the binomial coefficients one after another with the same update used for Pascal’s triangle, so it never needs factorials.
- Run the outer loop for
ifrom 0 ton − 1. - Set
c = 1, which is C(i, 0). - For
jfrom 0 toi: work outden = (i + 1) × c; print 1 ifdenis 1, otherwise1/den; then updatec = c × (i − j) / (j + 1). - Move to the next line.
Key takeaways
- Every entry is a unit fraction, so the program only computes denominators.
- The denominators are Pascal’s numbers times
i + 1. - Each fraction is the sum of the two below it: 1/2 = 1/3 + 1/6.
- Multiplying before dividing in the update keeps
ca whole number at every step.
Leibniz Harmonic Triangle in C
#include <stdio.h>
int main(void) {
int n = 5;
for (int i = 0; i < n; i++) {
int c = 1; /* C(i, j), starting with C(i, 0) */
for (int j = 0; j <= i; j++) {
int den = (i + 1) * c;
if (den == 1)
printf("1 ");
else
printf("1/%d ", den);
c = c * (i - j) / (j + 1);
}
printf("\n");
}
return 0;
}Leibniz Harmonic Triangle in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 0; i < n; i++) {
int c = 1; // C(i, j), starting with C(i, 0)
for (int j = 0; j <= i; j++) {
int den = (i + 1) * c;
if (den == 1)
cout << "1 ";
else
cout << "1/" << den << " ";
c = c * (i - j) / (j + 1);
}
cout << endl;
}
return 0;
}Leibniz Harmonic Triangle in Java
public class LeibnizHarmonicTriangle {
public static void main(String[] args) {
int n = 5;
for (int i = 0; i < n; i++) {
int c = 1; // C(i, j), starting with C(i, 0)
for (int j = 0; j <= i; j++) {
int den = (i + 1) * c;
if (den == 1)
System.out.print("1 ");
else
System.out.print("1/" + den + " ");
c = c * (i - j) / (j + 1);
}
System.out.println();
}
}
}Leibniz Harmonic Triangle in Python
n = 5
for i in range(n):
c = 1 # C(i, j), starting with C(i, 0)
for j in range(i + 1):
den = (i + 1) * c
print("1" if den == 1 else f"1/{den}", end=" ")
c = c * (i - j) // (j + 1)
print()Time and space complexity
Each fraction costs a few multiplications and one division, so the program runs in O(n²) time with O(1) extra memory.
Frequently asked questions
How can 1/2 equal 1/3 + 1/6?
Put both on a denominator of 6: 1/3 = 2/6, and 2/6 + 1/6 = 3/6 = 1/2. Every entry in the triangle works the same way with the two entries directly below it.
Why not print the fractions as decimals?
Most of them repeat forever: 1/3 is 0.333…, 1/6 is 0.1666…. Printing 1/den keeps the values exact and makes the pattern easier to see.
How far can the triangle go?
The largest denominator in row i is in the middle, and it grows quickly. With int the program is safe for about 15 rows; with a 64-bit type it goes much further.







