C # Finding the root of a quadratic equation

Source: Internet
Author: User

C # Finding the root of a quadratic equation


Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. threading. tasks; using System. windows. forms; namespace evaluate the root {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private double [] Root2 (double a, double B, double c) {double [] Roots = new double [2]; double Delt = B * B-4 * a * c; if (Delt> = 0) {Roots [0] = (-B + Math. sqrt (Delt)/2 * a; Roots [1] = (-B-Math. sqrt (Delt)/2 * a; return room ts;} else {room = null; return room ts;} private void button2_Click (object sender, EventArgs e) {Application. exit ();} private void button#click (object sender, EventArgs e) {if (Root2 (double. parse (textBox1.Text), double. parse (textBox2.Text), double. parse (textBo X3.Text) = null) {MessageBox. Show ("no real root! "," Error message ", MessageBoxButtons. OK, MessageBoxIcon. warning); return;} textBox4.Text = Root2 (double. parse (textBox1.Text), double. parse (textBox2.Text), double. parse (textBox3.Text) [0]. toString (); textBox5.Text = Root2 (double. parse (textBox1.Text), double. parse (textBox2.Text), double. parse (textBox3.Text) [1]. toString ();}}}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.