Q2 write a window application in C# to find out the even and odd number using user input.

It is said to be a number even when number is divided by 2 and remainder will be zero otherwise it is odd number. The form looks like as follows:

even-odd-numbers

Here textbox accept number and first it will be converted into integer number and assigned to the variable n. the code is as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CEvenOdd
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int n = Convert.ToInt32(textBox1.Text);
if (n % 2 == 0)
{
MessageBox.Show("Number is even", "Even or odd");
}
else
{
MessageBox.Show("Number is odd", "Even or odd");
}
}
}
}

In this program if n%2==0 then number is even otherwise number is odd.

MessageBox.Show() is used to show message box. The output is as follows:

even-odd-numbers