Q1 write a window application which takes the input from user and perform the addition of two numbers.

In this program we have added two numbers using the user input. The form looks like as follows:

addition-two-numbers

Here we have used two labels for taking the value of a and b as message. Now we have to add the code on button click. Here is the code:

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 AddNumbers
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a, b;
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
MessageBox.Show("Sum is : "+(a+b),"Addition" );
}
}
}

Here we have to give the code on button click event. Here we have a and b variable of int type which holds the value which are coming from textbox and here we have also performed the type conversion then the value assigned means textBox1.Text value will be hold by the a and textBox2.Text value will be hold by the b. after that we have added both and display it using the dialog. The output is as follows:

addition-two-numbers