C#求方程的根,题目要求无实根时带i.using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{class Program{static void Main(string[] args){string i = Console.ReadLine();string[] str =
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 19:21:08
C#求方程的根,题目要求无实根时带i.using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{class Program{static void Main(string[] args){string i = Console.ReadLine();string[] str =
C#求方程的根,题目要求无实根时带i.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string i = Console.ReadLine();
string[] str = i.Split();
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
int c = int.Parse(str[2]);
double k=b*b-4*a*c;
double j=Math.Sqrt(k);
double x1,x2,j2;
if (j > 0)
{
x1 = (-b + j) / 2.0 * a;
x2 = (-b - j) / 2.0 * a;
Console.WriteLine("x1={0} x2={1}",x1,x2);
}
else if (j == 0)
{
x1 = (-b) / 2.0 / a;
x2 = (-b) / 2.0 / a;
Console.WriteLine("x1={0} x2={1}",x1,x2);
}
else
{
}
}
}
}
写了一半了,就是无实根不会写.顺便看看我前面的有没有错?
C#求方程的根,题目要求无实根时带i.using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{class Program{static void Main(string[] args){string i = Console.ReadLine();string[] str =
double k=b*b-4*a*c; //后面开始分类讨论一下就可以了
int i=0;//标记位 ,记录是否有虚根,有的话1,没有就是0
if(k