Powers of 11 Pattern in C++

What You’ll Learn
How to print a simple numeric pattern where each row is multiplied by 11:
1, 11, 121, 1331, 14641.
This is a quick loop exercise and also a fun math pattern for beginners.
⭐ Pattern Output
For 5 rows, the pattern looks like this:
1
11
121
1331
14641Complete C++ Program
Start with 1 and multiply the running result by 11 on each next row.
#include <iostream>
using namespace std;
int main() {
int i, res = 1;
for (i = 1; i <= 5; i++) {
if (i == 1)
res = i;
else
res = res * 11;
cout << res;
cout << "\n";
}
return 0;
}🧠 How It Works
Initialize the result
We start with res = 1.
Loop over rows
The loop runs from i = 1 to 5 and prints one value per row.
Multiply by 11
From the second row onward, we compute res = res * 11.
Print the value
We output res and print a newline to move to the next row.
Powers of 11
This is a fast pattern to generate because each row is a single multiplication.
Variation — User Input Version
Let the user choose the number of rows. This version uses long long to reduce overflow risk (but it still overflows for larger rows).
#include <iostream>
using namespace std;
int main() {
int rows;
cout << "Enter the number of rows: ";
cin >> rows;
if (rows <= 0) return 0;
long long res = 1;
for (int i = 1; i <= rows; i++) {
if (i == 1) res = 1;
else res = res * 11;
cout << res << "\n";
}
return 0;
}💡 Tips for Enhancement
Try These
- Use
unsigned long longfor a slightly larger range - Use big integers (or strings) if you want many rows without overflow
- Print the values with commas for readability
- Compare these values to Pascal’s triangle for the first few rows
- Add overflow checks before multiplying by 11
Avoid
- Printing many rows with
int(overflow happens quickly) - Assuming the digits always match Pascal’s triangle (carry changes later rows)
- Not handling invalid input when reading
rows - Using
endlinside loops (unnecessary flushing)
Key Takeaways
Each next row is the previous value multiplied by 11.
Early rows match Pascal’s triangle digits (before carry starts).
Values overflow quickly in fixed-width integer types.
Time complexity is O(n) for n rows.
❓ Frequently Asked Questions
res = 1 and print it as the first row.1331 * 11 = 14641.Explore More C++ Number Patterns!
Patterns like this connect programming practice with neat math shortcuts—try experimenting with other multipliers too.
The first few powers of 11 visually encode binomial coefficients (Pascal’s triangle) before carry operations kick in.
12 people found this page helpful
