Print 1, 11, 121, 1331… in C#

Beginner
⏱️ 9 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Loops + Number Sequence

What You’ll Learn

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 C# examples, edge cases, and complexity.

Shape Rule

Multiply by 11

Each row is the previous value times 11 — starting from 1.

Single Loop

i = 1..n

for (i = 1; i <= n; i++) prints one value per row.

Running State

res variable

res holds the current number — update with res *= 11 after each print.

Pascal Link

Early rows only

First few values mirror binomial coefficients until base-10 carries break the pattern.

Live Preview

n = 3..8

Pick row count and generate the sequence in the browser.

O(n)

Complexity

One value per row — n prints total; extra memory stays O(1).

Introduction

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 C# a single loop runs i = 1..n, a variable res holds the current value, and you print then update with res *= 11.

Why it matters?

It teaches running state in a loop — a simpler pattern after Program 47’s nested diamond grids.

Key Highlights

Start at 1

res = 1 first row.

Times 11

res *= 11 each step.

vs Program 47

Program 47 is a 2D diamond; Program 48 is a 1D sequence.

Series Foundation

Follow Program 47; continue to Program 49 next.

In short: loop i = 1..n, print res, update res *= 11, then WriteLine().

📝 Problem & Approach

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.

C#
// n = 5
//1
//11
//121
//1331
//14641

Inputs & Outputs

ItemTypeDescription
nintHow many rows (values) to print.
resintRunning value — starts at 1, updated with res *= 11.
iintLoop counter from 1 to n.
Printed outputtextOne number per line — 1, 11, 121, …

Minimal workflow

Pseudocode
res = 1
for i from 1 to n:
    print res
    res = res * 11

Approach comparison

ApproachIdeaBest for
if/else on first rowif (i == 1) res = i; else res *= 11Matching classic textbook code
Print then multiplyWriteLine(res); res *= 11;Cleaner loop body — see Example 3
User-input nint.TryParse(...)Flexible row count
BigIntegerArbitrary-precision multiplyMany rows without overflow

⚡ Quick Reference

GoalPattern
Initializeint res = 1;
Loop rowsfor (i = 1; i <= n; i++)
Print valueConsole.WriteLine(res);
Update stateres *= 11; (or res = res * 11;)
Classic first-row checkif (i == 1) res = i; else res *= 11;
Cleaner variantPrint first, multiply after — no if needed
Program 47 contrastProgram 47 is a 2D diamond; Program 48 is a 1D sequence

📋 if/else vs User Input vs Print-Then-Multiply

Same sequence — three ways to structure the loop and set row count.

Classic
if (i == 1)

Special-case first row before multiply

User input
TryParse(n)

Read row count from console

Cleaner loop
print; res *= 11

No if/else — print then update

Large n
BigInteger

Avoid int overflow past ~row 10

Multiplier
* 11

Each step grows by one power of 11

Context

When This Pattern Shows Up

Reach for this pattern when teaching running state, sequence growth, and single-loop output.

  1. Post Program 47 exercise

    Natural follow-up after Program 47’s nested diamond — simpler 1D sequence with one loop.

  2. Running state

    res carries value from row to row — core loop-state pattern.

  3. Pascal connection

    Early rows mirror binomial coefficients until base-10 carries break the match.

  4. Gateway to variants

    Compare Program 47 (2D diamond) and Program 49 (next in series) next.

  5. Not a UI layout tool

    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.

🔮 Live Preview

Choose row count n between 3 and 8 and generate the powers-of-11 sequence in the browser.

Try 3, 5, or 8. Max up to 8 in this preview.

Live result
Press "Generate sequence".

Examples Gallery

Three complete C# programs — fixed rows, user input, and a cleaner print-then-multiply loop. Click View Output to reveal sample console results.

📚 Getting Started

Print five rows of the powers-of-11 sequence with the classic if/else first-row check.

Example 1 — Fixed n = 5

Hard-coded row count — matches the textbook version with if (i == 1).

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, res = 1;

            for (i = 1; i <= 5; i++)
            {
                if (i == 1)
                    res = i;
                else
                    res = res * 11;

                Console.Write(res);
                Console.WriteLine();
            }
        }
    }
}

How It Works

Row 1 sets res = 1 and prints it. Each later row multiplies res by 11 before printing — producing 11, 121, 1331, and 14641.

📈 User Input

Read row count n from the console with safe parsing.

Example 2 — User Input n

Read n from the console with int.TryParse — reject invalid input gracefully.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.Write("Enter number of rows: ");
            if (!int.TryParse(Console.ReadLine(), out n) || n <= 0)
            {
                Console.WriteLine("Please enter a positive integer.");
                return;
            }

            int res = 1;
            for (int i = 1; i <= n; i++)
            {
                if (i == 1)
                    res = 1;
                else
                    res = res * 11;

                Console.WriteLine(res);
            }
        }
    }
}

How It Works

Same multiply logic as Example 1; only the source of n changes. For large n, switch to BigInteger to avoid overflow.

⚡ Cleaner Loop

Print first, then multiply — no special-case if needed.

Example 3 — Print Then Multiply

Print res at the start of each iteration, then update with res *= 11.

C#
using System;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int res = 1;

            for (int i = 1; i <= 5; i++)
            {
                Console.WriteLine(res);
                res *= 11;
            }
        }
    }
}

How It Works

Because res starts at 1, the first print is correct without an if. Multiply happens after printing, so the next iteration gets the updated value.

🧠 How the Algorithm Prints Rows

1

Initialize result

int res = 1; holds the current value to print on each row.

Setup
2

Loop rows

for (i = 1; i <= n; i++) runs once per printed line.

Loop
3

Update state (classic)

First row: res = i. Later rows: res = res * 11 — or print first, then res *= 11.

State
4

Print value

Console.WriteLine(res) outputs one number per row.

Output
=

Sequence complete

One value per row — O(n) time, O(1) extra memory.

🔎 Worked Walkthrough — n = 5

Trace each iteration — what res holds before and after the multiply step (print-then-multiply variant).

iPrintsAfter res *= 11
1111
211121
31211331
4133114641
514641161051 (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.

Use Cases

Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.

1. Running State in Loops

Classic intro to carrying a value from iteration to iteration.

Example: trace the walkthrough table for n = 5.

2. Pattern Series Base

Follow Program 47’s diamond; continue to Program 49 next.

Example: compare 2D vs 1D pattern complexity.

3. Console Formatting Drills

Practice Write vs WriteLine with one value per row.

Example: use WriteLine(res) instead of Write + WriteLine().

4. Pascal / Binomial Link

Early rows mirror binomial coefficients — great math tie-in.

Example: row 5 prints 14641 = coefficients of (a+b)&sup4;.

5. Complexity Intuition

n rows, one print each — O(n) is easy to count.

Example: 5 rows = 5 prints total.

6. Overflow Awareness

Values grow fast — intro to BigInteger for larger n.

Example: row 10 exceeds int max — use BigInteger.

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.

Advantages

Why this pattern earns a permanent spot in beginner C# courses.

  1. 1. Single Loop Simplicity

    No nested loops — easier after Program 47’s diamond grid.

  2. 2. Minimal Concepts

    Only one loop, one variable, and console output — no arrays needed.

  3. 3. Easy to Extend

    Change n, swap to print-then-multiply, or use BigInteger for many rows.

  4. 4. O(1) Extra Memory

    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.

Usage Tips

Small habits that keep number-pattern code clean.

  1. 1. Initialize res = 1

    Start with 1 so the first printed value is correct.

  2. 2. Prefer TryParse

    Avoid crashes when the user types letters instead of a number.

  3. 3. Print Then Multiply

    Cleaner than if (i == 1) — see Example 3.

  4. 4. Use BigInteger for Large n

    int overflows around row 10 — switch to arbitrary precision.

  5. 5. Dry-Run n = 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.

Common Pitfalls

Mistakes that commonly break powers-of-11 sequence patterns.

  1. 1. Multiplying Before First Print

    First row prints 11 instead of 1 if you multiply before printing.

    → Print first, then res *= 11 — or use the if (i == 1) check.

  2. 2. Forgetting to Update res

    Every row prints 1 if you never multiply.

    → Add res = res * 11 or res *= 11 each iteration.

  3. 3. int Overflow

    Values exceed int.MaxValue around row 10.

    → Use System.Numerics.BigInteger for larger row counts.

  4. 4. Wrong Multiplier

    Using 10 or 12 instead of 11 produces a different sequence.

    → Confirm the pattern requires multiply-by-11.

  5. 5. Blind Convert.ToInt32

    Letters or empty input throw FormatException.

    → Prefer int.TryParse and re-prompt on failure.

Edge Cases

Check these inputs before calling the solution done.

n = 1

Single row

Output is just 1 on one line.

n = 0

Empty output

Loop never runs — print nothing or show a message.

Negative

n < 0

Treat as invalid; re-prompt instead of silent empty output.

n = 5

Classic demo

1, 11, 121, 1331, 14641 — last row before carry breaks Pascal match.

Bad input

Non-numeric ReadLine

Convert.ToInt32 throws — use TryParse.

Large n

Overflow risk

Values grow exponentially — use BigInteger past ~row 10.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Compare with Program 47

  • Program 47 uses nested loops for a 2D diamond
  • Program 48 uses one loop and running state

2. Change n

  • Try n = 3 or n = 8 in the live preview
  • Same loop, different row count

3. Next in series

  • Continue with Program 49
  • Build on sequence patterns

4. BigInteger version

  • Rewrite with BigInteger res = 1
  • Print 15+ rows without overflow

Notes

  • Running state. res carries the current value — update with res *= 11 after each print (or before, with an if-check).
  • Console.WriteLine(res) is cleaner than Write(res) + empty WriteLine().
  • Validate 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 i = 1..n, print res, update res *= 11, then WriteLine().

⏱️ Time and Space Complexity

ProgramTimeExtra space
Single loop (Examples 1–3)O(n)O(1)
BigInteger variantO(n × d) where d = digit countO(d) for stored value
Wrap Up

🎉 Conclusion

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 if (i == 1) in the classic variant. Both produce the same first five rows.

💡 Best Practices

✅ Do

  • Initialize res = 1 before the loop
  • Print then res *= 11 for a clean loop body
  • Use int.TryParse for user input
  • Switch to BigInteger for many rows
  • Validate n > 0 for interactive programs

❌ Don’t

  • Multiply before the first print without an if-check
  • Forget to update res each iteration
  • Use int for row counts that cause overflow
  • Ignore bad console input in user-facing demos
  • Skip the walkthrough trace before coding

Key Takeaways

Knowledge Unlocked

Five things to remember about this powers-of-11 sequence

Print the pattern the beginner-friendly way.

5
Core concepts
02

Start

res = 1

Code
03

Loop

i = 1..n

Code
04

Output

One value per line

Logic
O 05

Complexity

O(n) time

Analysis

❓ Frequently Asked Questions

It starts with res = 1 and, for each next row, multiplies res by 11. This produces 1, 11, 121, 1331, 14641 for the first 5 lines.
Yes — increase the loop limit or read n from user input. For many rows, switch to BigInteger because values grow quickly.
11^n shows binomial coefficients only while there are no carry-overs in base-10. Once carries occur, digits no longer match the triangle.
O(n) for n rows because the program computes and prints one value per row.
Program 47 prints a 2D concentric number diamond with nested loops. Program 48 prints a 1D growing sequence with one loop.
Yes — int overflows around row 10 (14641 * 11^5 exceeds int max). Use BigInteger for larger n.
Yes — print res first, then multiply: Console.WriteLine(res); res *= 11; — see Example 3.
161051 — still valid, but digit carries mean it no longer mirrors Pascal row 5 coefficients.
No — a single loop with a running variable is enough for this sequence pattern.

Did you Know? 🔊

Start with res = 1, print it, then update with res = res * 11 each row. For the first five rows you get 1, 11, 121, 1331, 14641 — one value per line, O(n) time.

Continue to Program 49

Move on to the next pattern in the C# number-pattern series.

Program 49 tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful