平方根线不起作用 [英] Square root line doesn’t work
本文介绍了平方根线不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个快速的代码来分解公式,但是用这条线创建D的平方根是行不通的.该行是第10行.不胜感激.
I wrote a quick code for factorizing formulas, however the line that takes creates the square root of D doesn’t work. The line is line 10. Any help is appreciated.
using System;
public class MainClass {
//Source Numbers
public int A = 1;
public int B = 3;
public int C = 9;
//Calculation Numbers
public float Di;
public static double Sqrt(double Di); //This is the faulted line.
//Answers
public float X;
public float X1;
public float X2;
public static void Main() {
Console.Writeline("D=", Di);
//Calculation for the Square root of D
// (DSq)Math.Sqrt(Di);
Di = B^2-4*A*C;
//Calculation for the answers
if(Di>0) {
X1 = ((0-B)-DSq)/(A*2);
X2 = ((0-B)+DSq)/(A*2);
Console.Writeline("X=", X1, " or X=", X2);
}
else if(Di=0) {
X = 0-B;
Console.Writeline("X=", X);
}
else {
Console.Writeline("The formula cannot be solved.");
}
}
}
推荐答案
您正在使用没有主体的方法定义.无论如何,您都不需要发明轮子,因为Math
已经具有Math.Sqrt()
方法.试试:
You are using a method definition with no body. In any case you dont need to invent the wheel, since Math
has already a Math.Sqrt()
, method. Try:
........
Di = B^2-4*A*C;
if (Di>0)
{
var sqrDi = Math.Sqrt(Di);
.....
}
...
这篇关于平方根线不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文