C# Natural Number Program

Beginner
5 min read
Updated: Oct 2026
2 programs
Live preview

What Is a Natural Number?

Natural numbers are the counting numbers. On this page we use the school-friendly rule: an integer is natural when n > 0 (that is, 1, 2, 3, …).

Remember
n is natural  ⇔  n is an integer and n > 0

Examples:
  1  → natural
  42 → natural
  0  → not natural (this page)
 -3  → not natural

Note: some syllabi include 0. Always state your definition.
nCheckResult
55 > 0Natural
11 > 0Natural
00 > 0 is falseNot natural
-2-2 > 0 is falseNot natural

How to Check a Natural Number in C#

Three clear steps — then either classify one value or list a range.

  1. State the definition you will use (here: n > 0).
  2. Compare the integer against zero and return a boolean.
  3. Optionally loop from 1 to N to print natural numbers in a range.
TaskIdeaTimeBest for
Single checkreturn n > 0;O(1)Yes/no classification
Range printLoop i from 1 to NO(N)Listing counting numbers

Pseudocode

Pseudocode
function IsNatural(n):
    return n > 0

function PrintNaturals(limit):
    for i from 1 to limit:
        print i

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
This page rulen > 0
Alternate rulen >= 0 (includes zero)
Set{1, 2, 3, …}
ZeroNot natural here — say so in interviews
NegativesNever natural under either common rule
Helper tipReturn bool; let Main print the message

Live Preview

Enter any integer to see whether it is natural under n > 0.

Whole numbers only. Tap a chip or type a value.

Result
n = 5
Check: 5 > 0 → true
Verdict: NATURAL NUMBER

Worked Walkthrough — n = 5 and n = 0

Apply the same comparison to a yes case and a boundary case.

Calculation
Case A: n = 5
  5 > 0 ? yes → natural

Case B: n = 0
  0 > 0 ? no  → not natural (on this page)

Case C: n = -3
  -3 > 0 ? no → not natural

C# Programs

Start with a boolean helper for one value. Then print natural numbers from 1 to 10 with a simple loop.

Example 1 — Single Check

Return true when the integer is greater than zero.

C#
using System;

class Program
{
    static bool IsNatural(int n)
    {
        return n > 0;
    }

    static void Main()
    {
        int number = 5;
        if (IsNatural(number))
        {
            Console.WriteLine(number + " is a Natural Number.");
        }
        else
        {
            Console.WriteLine(number + " is not a Natural Number.");
        }
    }
}

How It Works

  1. IsNatural encodes the page rule in one comparison: n > 0.
  2. No loop is needed — the answer is a single boolean.
  3. Main calls the helper and prints a clear message.
  4. For 5, the check is true, so the program reports a natural number.
  5. Swap in 0 or a negative to see the not-natural branch.

Example 2 — Print Natural Numbers 1 to 10

Natural numbers start at 1, so a forward loop from 1 through 10 lists them.

C#
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Natural numbers from 1 to 10:");
        for (int i = 1; i <= 10; i++)
        {
            Console.Write(i + " ");
        }
    }
}

How It Works

  1. Start at i = 1 because this page excludes zero.
  2. The loop condition i <= 10 keeps the end inclusive.
  3. Each pass prints the current natural number and a space.
  4. After i becomes 11, the loop stops.
  5. Change 10 to any positive limit to print a longer range.

Edge Cases & Pitfalls

Check these before calling the solution done.

Zero

Definition debate

Under n > 0, zero is not natural. Say your rule out loud in interviews.

Negatives

Always false

Negative integers are never natural under the common school definitions.

Decimals

Integers only

This page classifies int values. Floating-point input needs a different conversation.

Range start

Begin at 1

If you start a print loop at 0, you are listing whole numbers, not this page’s naturals.

Time and Space Complexity

ProgramTimeExtra space
Single checkO(1)O(1)
Print 1 to NO(N)O(1)

Key Takeaways

  • Definition: natural means n > 0 on this page.
  • Check: one comparison is enough — no loops required.
  • List: print from 1 to N with a forward for loop.
  • Test set: 1 and 5 natural; 0 and −3 not natural.

One line: if n > 0, it is a natural number under this tutorial’s rule.

Frequently Asked Questions

On this page, a natural number is a positive integer: 1, 2, 3, and so on. The check is simply n > 0.
It depends on the textbook. Some include 0. This tutorial uses n > 0, so 0 is not natural here.
No. Negative integers fail n > 0.
No. Natural numbers are whole counting numbers. Values like 1.5 are out of scope.
Change the rule to n >= 0 and say so in your explanation. Keep the code and wording aligned.
A single check is O(1). Printing natural numbers from 1 to N is O(N).

Next: Number Combination

Generate combinations of numbers for interview practice.

Number combination 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.

6 people found this page helpful