## Sunday, 26 March 2017

### Simple program

Simple program #3 (Print even and odd number upto n)

Even number upto: 20 are:
2 4 6 8 10 12 14 16 18 20
Odd number upto: 20 are:
1 3 5 7 9 11 13 15 17 19

The program is written in C# programming language and will accept a number as input. The logic of the program is to print even and odd number up to n.

 Simple program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code the program.

Practical Implementation:

using System;

namespace patternProblem.Simple_program
{
class Simple3   //Print even and odd number upto n
{
static void Main(string[] args)
{
Console.Write("Enter a number upto which you want to print even and odd number: ");
Console.WriteLine();

Console.WriteLine("-----Output-----");

Console.WriteLine();
Console.WriteLine("Even number upto: {0} are: ", n);

for (int i = 1; i <= n; i++)
{
if (i % 2 == 0)
{
Console.Write(i + " ");
}
}

Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Odd number upto: {0} are: ", n);

for (int i = 1; i <= n; i++)
{
if (i % 2 != 0)
{
Console.Write(i + " ");
}
}

Console.WriteLine();
}
}
}

Output:
The input number here is 20. So, the program will print even and odd number separately upto 20. The output is shown below:

Enter a number upto which you want to print even and odd number:
20

Even number upto: 20 are:
2 4 6 8 10 12 14 16 18 20
Odd number upto: 20 are:
1 3 5 7 9 11 13 15 17 19
Press any key to continue . . .

For any query, comment us below.

Previous - Simple program #2

Next – Simple program #4

Click imagination hunt to read latest blogs.

Keep learning and sharing...