public void DivTest() { //check div(int a, int b) Assert.AreEqual(5, OwnMath.div(10, 2)); Assert.AreEqual(-5, OwnMath.div(-10, 2)); Assert.AreEqual(0, OwnMath.div(0, 2)); Assert.ThrowsException <Exception>(() => (OwnMath.div(2, 0))); //check div(double a, int b) Assert.AreEqual(5.25, OwnMath.div(10.5, 2)); Assert.AreEqual(-5.25, OwnMath.div(-10.5, 2)); Assert.AreEqual(0, OwnMath.div(0.0, 2)); Assert.ThrowsException <Exception>(() => (OwnMath.div(2.5, 0))); //check div(int a, double b) Assert.AreEqual(4, OwnMath.div(10, 2.5)); Assert.AreEqual(-4, OwnMath.div(-10, 2.5)); Assert.AreEqual(0, OwnMath.div(0, 2.5)); //check mul(double a, double b) Assert.AreEqual(4.2, OwnMath.div(10.5, 2.5)); Assert.AreEqual(-4.2, OwnMath.div(-10.5, 2.5)); //check divInt(int a, int b) Assert.AreEqual(5, OwnMath.divInt(10, 2)); Assert.AreEqual(-5, OwnMath.divInt(-10, 2)); Assert.AreEqual(0, OwnMath.divInt(0, 2)); Assert.ThrowsException <Exception>(() => (OwnMath.divInt(2, 0))); }
static void Main(string[] args) { double output; List <double> numbers = new List <double>(); string[] inputs = Console.ReadLine().Replace('.', ',').Split(Separator); int strlen = inputs.Length; double tmp = 0; for (int i = 0; i < strlen; i++) { if (inputs[i] != string.Empty) { if (!double.TryParse(inputs[i], out tmp)) { continue; } numbers.Add(tmp); } } double N = numbers.Count; double x_carka; tmp = 0; for (int i = 0; i < N; i++) { tmp = OwnMath.add(tmp, numbers[i]); } x_carka = OwnMath.mul(OwnMath.div(1, N), tmp); tmp = 0; for (int i = 0; i < N; i++) { tmp = OwnMath.add(tmp, OwnMath.pow(numbers[i], 2)); } output = OwnMath.sqrt(OwnMath.mul(OwnMath.div(1, OwnMath.sub(N, 1)), OwnMath.sub(tmp, OwnMath.mul(N, OwnMath.pow(x_carka, 2))))); Console.WriteLine(output); }