← Back to Article List         
C# Read, ReadLine, Write & WriteLine

C# Read, ReadLine, Write & WriteLine

Published on 07 Oct 2026     4 min read C#
ReadLine - WriteLine

15 Simple C# Exercises with Answers

These are beginner-level exercises, suitable for practicing variables, input/output, operators, conditions, and loops.

1. Print Your Name

Question: Write a C# program to print your name.

Answer:

Console.WriteLine("Benazir");

2. Read and Display a Name

Question: Get a name from the user and display it.

Answer:

Console.Write("Enter your name: ");
string name = Console.ReadLine();

Console.WriteLine("Hello " + name);

3. Add Two Numbers

Question: Get two numbers from the user and display their sum.

Answer:

Console.Write("Enter first number: ");
int a = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter second number: ");
int b = Convert.ToInt32(Console.ReadLine());

int sum = a + b;

Console.WriteLine("Sum = " + sum);

4. Perform Basic Arithmetic Operations

Question: Get two numbers and display addition, subtraction, multiplication, and division.

Answer:

int a = 20;
int b = 5;

Console.WriteLine("Addition = " + (a + b));
Console.WriteLine("Subtraction = " + (a - b));
Console.WriteLine("Multiplication = " + (a * b));
Console.WriteLine("Division = " + (a / b));

5. Find Even or Odd

Question: Check whether a number is even or odd.

Answer:

Console.Write("Enter a number: ");
int number = Convert.ToInt32(Console.ReadLine());

if (number % 2 == 0)
{
    Console.WriteLine("Even Number");
}
else
{
    Console.WriteLine("Odd Number");
}

6. Find Positive, Negative, or Zero

Question: Check whether a number is positive, negative, or zero.

Answer:

Console.Write("Enter a number: ");
int number = Convert.ToInt32(Console.ReadLine());

if (number > 0)
{
    Console.WriteLine("Positive");
}
else if (number < 0)
{
    Console.WriteLine("Negative");
}
else
{
    Console.WriteLine("Zero");
}

7. Find the Largest of Two Numbers

Question: Get two numbers and display the largest.

Answer:

int a = 10;
int b = 20;

if (a > b)
{
    Console.WriteLine(a + " is largest");
}
else
{
    Console.WriteLine(b + " is largest");
}

8. Find the Largest of Three Numbers

Question: Find the largest among three numbers.

Answer:

int a = 10;
int b = 30;
int c = 20;

if (a >= b && a >= c)
{
    Console.WriteLine(a + " is largest");
}
else if (b >= a && b >= c)
{
    Console.WriteLine(b + " is largest");
}
else
{
    Console.WriteLine(c + " is largest");
}

9. Check Voting Eligibility

Question: Get the user's age and check whether they are eligible to vote.

Answer:

Console.Write("Enter your age: ");
int age = Convert.ToInt32(Console.ReadLine());

if (age >= 18)
{
    Console.WriteLine("Eligible to vote");
}
else
{
    Console.WriteLine("Not eligible to vote");
}

10. Print Numbers from 1 to 10

Question: Use a for loop to print numbers from 1 to 10.

Answer:

for (int i = 1; i <= 10; i++)
{
    Console.WriteLine(i);
}

11. Print Even Numbers from 1 to 20

Question: Display all even numbers between 1 and 20.

Answer:

for (int i = 1; i <= 20; i++)
{
    if (i % 2 == 0)
    {
        Console.WriteLine(i);
    }
}

12. Find the Sum from 1 to 10

Question: Calculate the sum of numbers from 1 to 10.

Answer:

int sum = 0;

for (int i = 1; i <= 10; i++)
{
    sum = sum + i;
}

Console.WriteLine("Sum = " + sum);

Output:

Sum = 55

13. Print a Multiplication Table

Question: Get a number and print its multiplication table.

Answer:

Console.Write("Enter a number: ");
int number = Convert.ToInt32(Console.ReadLine());

for (int i = 1; i <= 10; i++)
{
    Console.WriteLine(number + " x " + i + " = " + (number * i));
}

For input 5:

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50

14. Calculate Simple Interest

Question: Calculate simple interest using:

Simple Interest = (Principal × Rate × Time) / 100

Answer:

double principal = 10000;
double rate = 5;
double time = 2;

double interest = (principal * rate * time) / 100;

Console.WriteLine("Simple Interest = " + interest);

Output:

Simple Interest = 1000

15. Simple Grade Calculator

Question: Get a student's mark and display the grade.

  • 90–100 → A
  • 80–89 → B
  • 70–79 → C
  • 60–69 → D
  • Below 60 → Fail

Answer:

Console.Write("Enter your mark: ");
int mark = Convert.ToInt32(Console.ReadLine());

if (mark >= 90)
{
    Console.WriteLine("Grade A");
}
else if (mark >= 80)
{
    Console.WriteLine("Grade B");
}
else if (mark >= 70)
{
    Console.WriteLine("Grade C");
}
else if (mark >= 60)
{
    Console.WriteLine("Grade D");
}
else
{
    Console.WriteLine("Fail");
}

These 15 exercises cover the main C# beginner fundamentals: Console.WriteLine, Console.ReadLine, variables, data types, arithmetic operators, %, if/else, logical operators, and for loops.