Column-wise Floyd’s triangle fills the numbers 1 to 15 down the columns instead of across the rows. The first column reads 1 2 3 4 5, the second 6 7 8 9, and so on.
Quick answer: Start each row with value = i, because the first column simply counts 1 to n. Then, for each step to the right, add the length of the column you just left: value += n − j. On row 3 that gives 3, then 3 + 4 = 7, then 7 + 3 = 10.
This program is part of the Series Patterns collection.
Table of contents8 sections
Column-Wise Floyd’s Triangle output
Output (n = 5):
1 2 6 3 7 10 4 8 11 13 5 9 12 14 15

How the column-wise floyd’s triangle works
You cannot print a column at a time on a console, so the program has to work out each row directly. Column j holds n − j + 1 numbers. Moving one column to the right therefore jumps over the rest of the current column and the start of the next one, which adds up to n − j. Starting from i in the first column and adding these gaps gives every value in row i without any array.
- Run the outer loop for
ifrom 1 ton. - Set
value = iat the start of the row. - For
jfrom 1 toi: printvaluethree characters wide, then addn − jto it. - Move to the next line.
Key takeaways
- The first column is just 1 to
n, so each row starts atvalue = i. - The gap between neighbours shrinks by one per column: 4, 3, 2, 1 for five rows.
- No array is needed even though the numbers run down the columns.
- The last number is still
n(n + 1) / 2, as in the normal Floyd’s triangle.
Column-Wise Floyd’s Triangle in C
#include <stdio.h>
int main(void) {
int n = 5;
for (int i = 1; i <= n; i++) {
int value = i;
for (int j = 1; j <= i; j++) {
printf("%3d", value);
value += n - j;
}
printf("\n");
}
return 0;
}Column-Wise Floyd’s Triangle in C++
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
int value = i;
for (int j = 1; j <= i; j++) {
cout << setw(3) << value;
value += n - j;
}
cout << endl;
}
return 0;
}Column-Wise Floyd’s Triangle in Java
public class ColumnWiseFloydsTriangle {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
int value = i;
for (int j = 1; j <= i; j++) {
System.out.printf("%3d", value);
value += n - j;
}
System.out.println();
}
}
}Column-Wise Floyd’s Triangle in Python
n = 5
for i in range(1, n + 1):
value = i
for j in range(1, i + 1):
print(f"{value:3d}", end="")
value += n - j
print()Time and space complexity
Each number takes one addition, so the program runs in O(n²) time for n rows and needs only O(1) extra memory.
Frequently asked questions
How is this different from Floyd’s triangle?
Floyd’s triangle fills the numbers row by row: 1, then 2 3, then 4 5 6. This version fills them column by column, so the rows read 1, 2 6, 3 7 10. Both use the same 15 numbers and the same triangle shape.
Why is the gap n − j?
Column j holds n − j + 1 numbers. From row i in column j to row i in the next column you pass the rest of column j and the first part of column j + 1. Those two pieces always add up to n − j.
Could I use a two-dimensional array instead?
Yes: fill an n × n array column by column with a counter, then print the lower triangle row by row. It is easier to picture but uses O(n²) memory, while the formula needs none.










