(a-b+c)²
=(a+c-b)²
=(a+c)²-2b(a+c)+b²
=a²+2ac+c²-2ab-2bc+b²
=a²+b²+c²-2ab-2bc+2ac
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double a, b, c,X,y;
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
c = Convert.ToInt32(textBox3.Text);
X = a - b - c;
y = Math.Pow(X, 2);
MessageBox.Show("y="+y);
}
}
} 照样子见一个窗体,输入代码!
先把a-b看到一个整体,如下:
[(a-b)+c]^2=(a-b)^2+2(a-b)*c+c^2
(a-b+c)^2 = a^2 + b^2 + c^2 - 2ab - 2bc + 2ac
直接去括号呗!