Write a C program that uses a form that contains the followi
Write a C# program that uses a form that contains the following: a textbox, where the user enters an integer number a button, when clicked the code will call a method named calculate_sum, that will find the sum of the numbers from 1 up to and including the number entered by the user in the textbox. after the method finishes executing, the code will display the sum of the numbers in a MessageBox. If the user types 5 in the textbox, then the code will find the sum of the numbers from 1 to 5. which equals 15.
Solution
using System; using System.Windows.Forms; namespace WindowsFormsApplication21 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { this.Text = textBox1.Text; } private void button1_Click(object sender, EventArgs e) { int s=0,i=1; n=Integer.ParseInt(textBox1.Text); for(i=1;i<=n;i++) s=s+i; MessageBox.Show(\"Sum of the numbers is \",+s); } } }