The Lucas number triangle lays the Lucas series out in rows: 2, then 1 3, then 4 7 11. The Lucas numbers follow the same rule as the Fibonacci numbers, each one the sum of the two before it, but they start with 2 and 1.
Quick answer: Keep two running values, a = 2 and b = 1. Row i prints i numbers: print a, then move on with next = a + b; a = b; b = next. The only difference from the Fibonacci triangle is the starting pair.
This program is part of the Series Patterns collection.
Table of contents8 sections
Lucas Number Triangle output
Output (n = 5):
2 1 3 4 7 11 18 29 47 76 123 199 322 521 843

How the lucas number triangle works
Édouard Lucas, the French mathematician who also named the Fibonacci sequence, studied this series in the 1870s. The code is the Fibonacci triangle with a different start: the two running values carry the series through the whole triangle, so each row continues from where the last one stopped. Five rows use the first fifteen Lucas numbers, ending at 843.
- Set
a = 2andb = 1before the loops. - Run the outer loop for
ifrom 1 ton. - Repeat
itimes: printafour characters wide, then setnext = a + b,a = b,b = next. - Move to the next line.
Key takeaways
- Lucas numbers use the Fibonacci rule with the start 2, 1.
- The running values sit outside the loops, so the series continues across rows.
- Lucas and Fibonacci numbers are linked: L(n) = F(n − 1) + F(n + 1).
- Printing four characters wide keeps the columns straight up to 9999.
Lucas Number Triangle in C
#include <stdio.h>
int main(void) {
int n = 5;
int a = 2, b = 1; /* the Lucas series starts 2, 1 */
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
printf("%4d", a);
int next = a + b;
a = b;
b = next;
}
printf("\n");
}
return 0;
}Lucas Number Triangle in C++
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n = 5;
int a = 2, b = 1; // the Lucas series starts 2, 1
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cout << setw(4) << a;
int next = a + b;
a = b;
b = next;
}
cout << endl;
}
return 0;
}Lucas Number Triangle in Java
public class LucasNumberTriangle {
public static void main(String[] args) {
int n = 5;
int a = 2, b = 1; // the Lucas series starts 2, 1
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.printf("%4d", a);
int next = a + b;
a = b;
b = next;
}
System.out.println();
}
}
}Lucas Number Triangle in Python
n = 5
a, b = 2, 1 # the Lucas series starts 2, 1
for i in range(1, n + 1):
for j in range(i):
print(f"{a:4d}", end="")
a, b = b, a + b
print()Time and space complexity
Each of the n(n + 1)/2 terms costs one addition, so the program runs in O(n²) time with O(1) extra memory.
Frequently asked questions
How are Lucas numbers related to Fibonacci numbers?
Each Lucas number is the sum of the two Fibonacci numbers on either side of it: L(n) = F(n − 1) + F(n + 1). For example L(4) = 7 = F(3) + F(5) = 2 + 5.
Why does the series go 2, 1, 3 and not 1, 2, 3?
That is how Lucas defined it: L(0) = 2 and L(1) = 1. The next terms follow from the addition rule: 2 + 1 = 3, 1 + 3 = 4, 3 + 4 = 7.
How many rows fit in an int?
Lucas numbers grow at the same rate as Fibonacci numbers, so an int is safe for about nine rows. Use long long or long for more.







