C# Whole Number Program

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

What Is a Whole Number?

A whole number is a counting number plus zero. On this page we use the school-friendly rule: an integer is whole when n >= 0 (that is, 0, 1, 2, 3, …).

Remember
n is whole  ⇔  n is an integer and n >= 0

Examples:
  0  → whole
  1  → whole
 42  → whole
 -3  → not whole

Natural numbers (this site) use n > 0, so 0 is the only difference.
nCheckResult
55 >= 0Whole
11 >= 0Whole
00 >= 0 is trueWhole
-2-2 >= 0 is falseNot whole

How to Check a Whole 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 0 to N to print whole numbers in a range.
TaskIdeaTimeBest for
Single checkreturn n >= 0;O(1)Yes/no classification
Range printLoop i from 0 to NO(N)Listing whole numbers

Pseudocode

Pseudocode
function IsWhole(n):
    return n >= 0

function PrintWholes(limit):
    for i from 0 to limit:
        print i

Cheat Sheet

Keep these facts handy while writing the program.

TopicDetail
This page rulen >= 0
Natural rulen > 0 (excludes zero)
Set{0, 1, 2, 3, …}
ZeroWhole, but not natural
NegativesNever whole
Helper tipReturn bool; let Main print the message

Whole vs Natural

nNatural (n > 0)Whole (n >= 0)
5YesYes
0NoYes
-3NoNo

Live Preview

Enter any integer to see whether it is whole under n >= 0 and how that compares with natural.

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

Result
n = 0
Check: 0 >= 0 → true
Natural (n > 0): false
Verdict: WHOLE NUMBER

Worked Walkthrough — n = 5, n = 0, n = -3

Apply the same comparison to a yes case, the zero boundary, and a negative.

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

Case B: n = 0
  0 >= 0 ? yes → whole  (natural would say no)

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

C# Programs

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

Example 1 — Single Check

Return true when the integer is greater than or equal to zero.

C#
using System;

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

    static void Main()
    {
        int number = 0;
        if (IsWhole(number))
        {
            Console.WriteLine(number + " is a Whole Number.");
        }
        else
        {
            Console.WriteLine(number + " is not a Whole Number.");
        }
    }
}

How It Works

  1. IsWhole 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 0, the check is true, so the program reports a whole number (a natural check would say no).
  5. Swap in 5 or a negative to see the other branches.

Example 2 — Print Whole Numbers 0 to 10

Whole numbers start at 0, so a forward loop from 0 through 10 lists them.

C#
using System;

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

How It Works

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

Edge Cases & Pitfalls

Check these before calling the solution done.

Zero

Whole, not natural

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

Negatives

Always false

Negative integers are never whole numbers.

Decimals

Integers only

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

Range start

Begin at 0

If you start a print loop at 1, you are listing natural numbers, not whole numbers.

Time and Space Complexity

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

Key Takeaways

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

One line: if n >= 0, it is a whole number — natural numbers plus zero.

Frequently Asked Questions

On this page, a whole number is a nonnegative integer: 0, 1, 2, 3, and so on. The check is simply n >= 0.
Yes. Zero is the one number that is whole but not natural (natural uses n > 0 on this site).
No. Negative integers fail n >= 0.
No. Whole numbers have no fractional part. Values like 1.5 are out of scope.
Natural numbers use n > 0 (1, 2, 3, ...). Whole numbers use n >= 0 (0, 1, 2, 3, ...). Zero is the only difference.
A single check is O(1). Printing whole numbers from 0 to N is O(N).

Next: Number Combination

Generate combinations of numbers for interview practice.

Number combination tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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