two left
This commit is contained in:
53
labs/lab4_done/Utils/Operation.cs
Normal file
53
labs/lab4_done/Utils/Operation.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user