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:
Here textbox accept number and first it will be converted into integer number and assigned to the variable n. the code is as follows:
public partial class Form1 : Form
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");
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: