54 lines
1.1 KiB
C#
54 lines
1.1 KiB
C#
using System;
|
|
|
|
public class Operation
|
|
{
|
|
public static double TriangleArea(double a, double b, double c)
|
|
{
|
|
double p = (a + b + c) / 2;
|
|
bool exists = CheckTriangle(a, b, c);
|
|
if (!exists)
|
|
return -1;
|
|
|
|
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
|
|
}
|
|
|
|
public static double TriangleArea(double a)
|
|
{
|
|
return TriangleArea(a, a, a);
|
|
}
|
|
|
|
|
|
public static bool CheckTriangle(double a, double b, double c)
|
|
{
|
|
if (a <= 0 || b <= 0 || c <= 0) return false;
|
|
|
|
double maxSide = Math.Max(Math.Max(a, b), Math.Max(b, c));
|
|
|
|
if (maxSide >= a + b + c - maxSide) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public static int SolveQuadratic(int a, int b, int c, out double x1, out double x2)
|
|
{
|
|
double d = b * b - 4 * a * c;
|
|
if (d > 0)
|
|
{
|
|
x1 = (-b + Math.Sqrt(d)) / (2 * a);
|
|
x2 = (-b - Math.Sqrt(d)) / (2 * a);
|
|
return 1;
|
|
}
|
|
else if (d == 0)
|
|
{
|
|
x1 = x2 = -b / (2 * a);
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
x1 = x2 = -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
}
|