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/06/25 15:41:12
![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 =](/uploads/image/z/8620666-34-6.jpg?t=C%23%E6%B1%82%E6%96%B9%E7%A8%8B%E7%9A%84%E6%A0%B9%2C%E9%A2%98%E7%9B%AE%E8%A6%81%E6%B1%82%E6%97%A0%E5%AE%9E%E6%A0%B9%E6%97%B6%E5%B8%A6i.using+System%3Busing+System.Collections.Generic%3Busing+System.Linq%3Busing+System.Text%3Bnamespace+ConsoleApplication1%7Bclass+Program%7Bstatic+void+Main%28string%5B%5D+args%29%7Bstring+i+%3D+Console.ReadLine%28%29%3Bstring%5B%5D+str+%3D)
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