Home »
.Net »
C# Programs
C# - Even and Odd Numbers From 1 To 30
Learn: How to check whether a given number is EVEN or ODD? Here, we are implementing a program in C# .Net, which will check numbers from 1 to 30.
[Last updated : March 19, 2023]
To understand the program of even numbers, first we should understand the concept of even and odd numbers.
What are EVEN and ODD Numbers?
Even numbers are those numbers they are divisible by 2. And odd numbers are those numbers they are not divisible by 2. 0 is an even number.
For example:
- 1 is an odd number.
- 2 is an even number.
- 3 is an odd number.
- 4 is an even number.
C# program to print Even and Odd numbers from 1 to 30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i = 0;
Console.WriteLine("Even Numbers :");
for (i = 1; i <= 30; i++)
{
if( i%2 == 0 )
{
Console.Write(i + " ");
}
}
Console.WriteLine("\nOdd Numbers :");
for (i = 1; i <= 30; i++)
{
if (i % 2 != 0)
{
Console.Write(i + " ");
}
}
Console.WriteLine();
}
}
}
Output
Even Numbers :
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Odd Numbers :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
C# Basic Programs »