Print Floyd's Triangle
C++
Medium
2 views
Problem Description
Print numbers in triangular form (1, 2 3, 4 5 6...).
Real Life: Famous number pattern in mathematics.
Step-by-Step Logic:
1. Start counter from 1
2. Each row has row_number elements
3. Print and increment counter continuously
4. Natural number sequence in triangle
Official Solution
void pattern_q10_floyds_triangle() {
int n = 5;
int counter = 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++) {
cout << counter << " ";
counter++;
}
cout << endl;
}
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!