C#を使用して2次方程式の結果を計算しようとしましたが、結果はNaN
です。誰かが私のコードをチェックしてエラーを見つけることができますか?NaN計算結果
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace desafio2_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please insert the values that multiply x², x and the independent term respectively: ");
float a = float.Parse(Console.ReadLine());
float b = float.Parse(Console.ReadLine());
float c = float.Parse(Console.ReadLine());
double bhaskarap1 = (Math.Pow(b, 2)) + (- 4 * a * c);
double raiz1 = (-b + Math.Sqrt(bhaskarap1))/(2 * a);
double raiz2= (-b - Math.Sqrt(bhaskarap1))/(2 * a);
Console.WriteLine(raiz1);
Console.WriteLine(raiz2);
}
}
}
は、私たちは "b" と "c" は、変数 "A" のために入力した正確な数値を見ることができますか? –
[小さなプログラムをデバッグする方法を学ぶ必要があります](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)、あなたに問題を見つけるように頼むだけです。プログラムを試して勉強する恐ろしい方法。 –