Output Numbers from 1 to 10 in C#
Introduction
Table of Contents
In programming, one of the most common tasks is displaying a sequence of values. Whether it’s listing items, printing steps in order, or generating numbers, knowing how to output data in sequence is very important. In this lesson, we will learn how to display numbers from 1 to 10 using C#. This activity will help you understand how loops and program flow work, while also giving you confidence in writing simple, structured code. By practicing this, you will take another step forward in learning how computers repeat tasks efficiently and avoid repetitive coding.
Objectives
This lesson builds a strong habit of writing small, working programs. Your goal is to understand what the code does, learn the syntax for loops, practice by running and tweaking a sample program, and finally apply the idea by extending it to simple real‑world style tasks (like printing ranges or even numbers).
- Understand: Explain how a loop (for/while) works to print numbers in sequence.
- Learn: Identify and write the correct C# syntax for a for loop that counts from 1 to 10.
- Practice: Build and run a C# console app in VS Code that outputs numbers 1–10.
- Apply: Modify the program to print custom ranges or only even/odd numbers.
Beginner-Friendly Source Code & Step-by-Step Instructions
- Open VS Code. Make sure the .NET SDK is installed (dotnet –version in Terminal should show a number).
- Create/open your course folder (e.g., D:\2025-1_doe_bsis_1a).
- Open the folder in VS Code (File → Open Folder…).
- Open a new Terminal in VS Code (Terminal → New Terminal).
- Create a console project:
dotnet new console -n output_1_to_10 - Change directory into the project:
cd output_1_to_10 - Open Program.cs and replace its contents with the code below.
- Run the app:
dotnet run
Program.cs
using System; namespace NumbersOutputApp { class Program { static void Main(string[] args) { Console.WriteLine("Numbers from 1 to 10:"); Console.WriteLine(1); Console.WriteLine(2); Console.WriteLine(3); Console.WriteLine(4); Console.WriteLine(5); Console.WriteLine(6); Console.WriteLine(7); Console.WriteLine(8); Console.WriteLine(9); Console.WriteLine(10); } } }
Expected Output
1
2
3
4
5
6
7
8
9
10
Explanation of the Program
This simple program demonstrates how to display numbers from 1 to 10 using Console.WriteLine
in C#. The program begins by importing the System namespace, which allows us to use built-in methods like Console.WriteLine
. We then define a namespace (NumbersOutputApp
) and a class (Program
), which are required structures in C# to organize our code.
Inside the Main method, which is the starting point of every C# application, we first display a short heading to inform the user about what the program will do. After that, we print the numbers 1 through 10 one by one, without using loops. Each number is written as a separate Console.WriteLine
statement.
The purpose of this exercise is to help beginners become familiar with the basic structure of a C# program and the use of Console.WriteLine
for output. Although this approach is not efficient for larger tasks, it introduces the concept of outputting values to the console in the simplest way possible, before moving on to more advanced topics like loops.
Summary
In this lesson, you learned how to display numbers from 1 to 10 in C# without using loops. By writing multiple Console.WriteLine()
statements, you can control exactly what the program outputs. While this method works for small tasks, you will later see how loops make this process easier and more efficient.
Quiz
-
Which command is used to display output in C#?
A. Console.ReadLine()
B. Console.WriteLine()
C. Console.Input()
D. Console.Print() -
What is the correct way to display the number 5?
A. Console.WriteLine(“5”);
B. Console.Print(5);
C. WriteLine.Console(5);
D. System.Out(5); -
If you want to output numbers 1–10 without a loop, what must you do?
A. Use a while loop
B. Use multiple Console.WriteLine() statements
C. Use Console.PrintAll()
D. It’s not possible in C# -
What will happen if you forget to write
Console.WriteLine(10);
in the program?
A. Error occurs
B. Only numbers 1–9 are displayed
C. Nothing displays
D. Program won’t run at all -
Why is this approach (without loops) not recommended for larger sequences?
A. It makes code too repetitive and hard to maintain
B. It produces errors
C. It requires user input
D. It doesn’t display output
Exercises and Assessment
Intro
To strengthen your understanding of Console.WriteLine()
, here are exercises that will challenge you to modify and expand the code. These activities will prepare you for loop-based programming later.
Exercises
-
Modify the program to output numbers from 1 to 20.
-
Change the program to output even numbers only (2, 4, 6, … 20).
-
Display your name followed by your age and hobby after printing the numbers.
-
Write a program that outputs numbers in reverse (10 to 1).
-
Create a program that displays a sequence of 5 favorite numbers.
Assessment
-
Quiz: Answer the 5 multiple-choice questions.
-
Performance Task: Modify the code to print numbers from 50 to 60.
Lab Exam
-
Write a program in C# that prints numbers from 1 to 15 without using loops.
-
Output must show each number on a separate line.
You may visit our Facebook page for more information, inquiries, and comments. Please subscribe also to our YouTube Channel to receive free capstone projects resources and computer programming tutorials.
Hire our team to do the project.