二元一次方程求解,用c#程序设计怎么写
发布网友
发布时间:2024-05-15 14:09
我来回答
共1个回答
热心网友
时间:2024-06-02 10:07
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 方程式求解
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入二元一次方程组的系数(按a1x+b1y=c1,a2x+b2y=c2标准形式)");
Console.Write("a1:");
float a1 = (float)Convert.ToDouble(Console.ReadLine());
Console.Write("b1:");
float b1 = (float)Convert.ToDouble(Console.ReadLine());
Console.Write("c1:");
float c1 = (float)Convert.ToDouble(Console.ReadLine());
Console.Write("a2:");
float a2 = (float)Convert.ToDouble(Console.ReadLine());
Console.Write("b2:");
float b2 = (float)Convert.ToDouble(Console.ReadLine());
Console.Write("c2:");
float c2 = (float)Convert.ToDouble(Console.ReadLine());
float x1 = (c1 - c2 * (b1 / b2)) / (a1 - a2 * (b1 / b2));
float y1 = (c1 - a1 * x) / b1;
Console.WriteLine("此二元一次方程组的解为:x={0},y={1}",x1,y1);
Console.ReadKey();
}
}
}