Shape Rule
Multiply by 11
Each row is the previous value times 11 — starting from 1.

Program 48 prints the powers-of-11 sequence: 1, 11, 121, 1331, 14641 — a natural step after Program 47’s 2D concentric diamond. This tutorial covers a simple loop with running state (res *= 11), a live preview, worked JavaScript examples, edge cases, and complexity.
Multiply by 11
Each row is the previous value times 11 — starting from 1.
loop n times
for (let i = 0; i < n; i++) logs one value per row.
res variable
res holds the current number — update with res *= 11 after each print.
Early rows only
First few values mirror binomial coefficients until base-10 carries break the pattern.
n = 3..8
Pick row count and generate the sequence in the browser.
Complexity
One value per row — n prints total; extra memory stays O(1).
A powers-of-11 sequence prints one growing number per row: start at 1, then multiply by 11 for each next line. With n = 5, the output is 1, 11, 121, 1331, 14641.
In JavaScript a single loop runs n times, a variable res holds the current value, and you console.log(res) then update with res *= 11.
It teaches running state in a loop — a simpler pattern after Program 47’s nested diamond grids.
res = 1 first row.
res *= 11 each step.
Program 47 is a 2D diamond; Program 48 is a 1D sequence.
Follow Program 47; continue to Program 49 next.
In short: loop n times, console.log(res), then update with res *= 11.
Given row count n = 5, print the powers-of-11 sequence — one growing number per line, starting at 1 and multiplying by 11 each step.
// n = 5
// 1
// 11
// 121
// 1331
// 14641 | Item | Type | Description |
|---|---|---|
n | number | How many rows (values) to print. |
res | number | Running value — starts at 1, updated with res *= 11. |
power | number | Loop counter from 0 to n - 1 (exponentiation variant). |
| Printed output | text | One number per line — 1, 11, 121, … |
let res = 1;
for (let i = 0; i < n; i++) {
console.log(res);
res *= 11;
} | Approach | Idea | Best for |
|---|---|---|
| Print-then-multiply | console.log(res); res *= 11 | Cleaner loop body — see Example 1 |
| User-input n | parseInt(prompt()) | Flexible row count |
| Exponentiation | console.log(11 ** power) | Direct power per row — see Example 3 |
| Goal | Pattern |
|---|---|
| Initialize | let res = 1 |
| Loop rows | for (let i = 0; i < n; i++) |
| Print value | console.log(res) |
| Update state | res *= 11 |
| Exponentiation form | console.log(11 ** power) for power = 0..n-1 |
| Cleaner variant | Print first, multiply after — no special-case if needed |
| Program 47 contrast | Program 47 is a 2D diamond; Program 48 is a 1D sequence |
Same sequence — three ways to structure the loop and set row count.
res *= 11Running state updated each row
parseInt(prompt())Read row count from prompt()
11 ** powerDirect power per row — no state variable
BigIntUse BigInt for very large row counts
* 11Each step grows by one power of 11
Reach for this pattern when teaching running state, sequence growth, and single-loop output.
Natural follow-up after Program 47’s nested diamond — simpler 1D sequence with one loop.
res carries value from row to row — core loop-state pattern.
Early rows mirror binomial coefficients until base-10 carries break the match.
Compare Program 47 (2D diamond) and Program 49 (next in series) next.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in loop state, multiply-update logic, and O(n) thinking.
Choose row count n between 3 and 8 and generate the powers-of-11 sequence in the browser.
Three complete JavaScript programs — fixed n = 5, prompt() input, and exponentiation with 11 ** power. Click View Output to reveal sample console results, or Try it Yourself to run the code live.
Print five rows of the powers-of-11 sequence with print-then-multiply.
n = 5Hard-coded row count — print first, then multiply by 11.
let res = 1;
for (let i = 0; i < 5; i++) {
console.log(res);
res *= 11;
} res starts at 1 and prints on each iteration. After printing, res *= 11 prepares the next row — producing 11, 121, 1331, and 14641.
Read row count n with prompt() instead of hard-coding 5.
Read n with prompt() and reject non-positive values.
const nInput = prompt("Enter number of lines:");
const n = parseInt(nInput, 10);
if (!Number.isFinite(n) || n < 1) {
console.log("Please enter a positive integer.");
} else {
let res = 1;
for (let i = 0; i < n; i++) {
console.log(res);
res *= 11;
}
} Same multiply logic as Example 1; only the source of n changes. JavaScript handles large values for typical row counts; use BigInt for very long sequences.
Use 11 ** power directly — no running state variable needed.
Print 11 ** power for each power from 0 to n - 1.
const n = 5;
for (let power = 0; power < n; power++) {
console.log(11 ** power);
} 11 ** 0 is 1, 11 ** 1 is 11, and so on — same sequence without a running res variable.
res = 1 holds the current value to print on each row.
for (let i = 0; i < n; i++) runs once per printed line.
Log res first, then res *= 11 — or use console.log(11 ** power) directly.
console.log(res) outputs one number per row.
One value per row — O(n) time, O(1) extra memory.
n = 5Trace each iteration — what res holds before and after the multiply step (print-then-multiply variant).
i | Prints | After res *= 11 |
|---|---|---|
1 | 1 | 11 |
2 | 11 | 121 |
3 | 121 | 1331 |
4 | 1331 | 14641 |
5 | 14641 | 161051 (next row if continued) |
Row 6 would print 161051 — the first value where digit carries break the Pascal-triangle visual match, but the multiply loop still works correctly.
Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.
Classic intro to carrying a value from iteration to iteration.
Example: trace the walkthrough table for n = 5.
Follow Program 47’s diamond; continue to Program 49 next.
Example: compare 2D vs 1D pattern complexity.
Practice console.log() with one value per row.
Example: use console.log(res) for one value per line.
Early rows mirror binomial coefficients — great math tie-in.
Example: row 5 prints 14641 = coefficients of (a+b)&sup4;.
n rows, one print each — O(n) is easy to count.
Example: 5 rows = 5 prints total.
Values grow fast — use BigInt when numbers exceed safe integer limits.
Example: print 20+ rows — watch precision for very large values.
Pro Tip: when an interviewer asks for patterns, explain the state variable first — then write the loop. The story matters as much as the code.
Why this pattern earns a permanent spot in beginner JavaScript courses.
No nested loops — easier after Program 47’s diamond grid.
Only one loop, one variable, and console output — no arrays needed.
Change n, swap to exponentiation, or print many rows — use BigInt when needed.
Streaming output needs no storage beyond res and loop counter.
Pro Tip: trace the walkthrough table on paper — watch how res grows by one power of 11 each row.
Small habits that keep number-pattern code clean.
Start with 1 so the first printed value is correct.
Number.isFinite()Avoid crashes when the user types letters instead of a number.
Cleaner than special-casing the first row — see Example 1.
11 ** power is a clear alternative — see Example 3.
Trace three rows on paper before coding the full n = 5 demo.
Pro Tip: if values look wrong after row 1, check whether you multiply before or after printing.
Mistakes that commonly break powers-of-11 sequence patterns.
First row prints 11 instead of 1 if you multiply before printing.
→ Print first, then res *= 11.
Every row prints 1 if you never multiply.
→ Add res = res * 11 or res *= 11 each iteration.
Using pow(11, p) without casting can produce floats for large p.
→ Use 11 ** power with integers — switch to BigInt for very large powers.
Using 10 or 12 instead of 11 produces a different sequence.
→ Confirm the pattern requires multiply-by-11.
parseInt(prompt())Letters or empty input return NaN with bare parseInt(prompt()).
→ Catch ValueError and re-prompt on failure.
Check these inputs before calling the solution done.
Output is just 1 on one line.
Loop never runs — print nothing or show a message.
n < 0Treat as invalid; re-prompt instead of silent empty output.
1, 11, 121, 1331, 14641 — last row before carry breaks Pascal match.
Bare parseInt(prompt()) returns NaN — use Number.isFinite() first.
Values grow exponentially — use BigInt for very large row counts.
Try these variations to lock in the pattern.
console.log(11 ** power)res carries the current value — update with res *= 11 after each print (or before, with an if-check).console.log(res) logs one value per row cleanly.n > 0 for interactive programs; n = 1 prints a single 1.n rows, one print each — total work is O(n) with O(1) extra memory.Quick Takeaway: loop n times, console.log(res), then update with res *= 11.
| Program | Time | Extra space |
|---|---|---|
| Single loop (Examples 1–3) | O(n) | O(1) |
| Exponentiation (Example 3) | O(n × d) where d = digit count | O(d) for stored value |
The powers-of-11 sequence is a simple follow-up to Program 47: one loop, a running res variable, and multiply-by-11 each row. Master the fixed-n version, then try user input and the cleaner print-then-multiply loop.
Practice the three examples above, then continue to Program 49 for the next pattern in the series.
Print first, multiply after — or use 11 ** power for a stateless variant. Both produce the same first five rows.
let res = 1 before the loopres *= 11 for a clean loop bodyNumber.isFinite(n) after parseInt(prompt())11 ** power as an alternativen > 0 for interactive programsres each iterationpow(11, p) for large pPrint the pattern the beginner-friendly way.
res *= 11 each row
Definitionres = 1
Codeloop n times
CodeOne value per line
LogicO(n) time
AnalysisStart with let res = 1, log it, then update with res *= 11 each row. For the first five rows you get 1, 11, 121, 1331, 14641 — one value per line, O(n) time.
Move on to the next pattern in the JavaScript number-pattern series.
12 people found this page helpful