Пример #1
0
        public void PowTest()
        {
            //check Pow(int a, int power)
            Assert.AreEqual(9, OwnMath.pow(3, 2));
            Assert.AreEqual(9, OwnMath.pow(-3, 2));
            Assert.AreEqual(27, OwnMath.pow(3, 3));
            Assert.AreEqual(0, OwnMath.pow(0, 2));

            //check Pow(double a, double power)
            Assert.AreEqual(10.889999999999999, OwnMath.pow(3.3, 2));
            Assert.AreEqual(10.889999999999999, OwnMath.pow(-3.3, 2));
            Assert.AreEqual(0.0, OwnMath.pow(0.0, 2));
        }
Пример #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);
        }