Exemplo n.º 1
0
        static void Main()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-Us");
            string        s;
            List <double> numbers = new List <double>();
            double        x1 = 0, sum = 0, x2 = 0, x = 0, sum2 = 0;

            Math.Library.Math math = new Math.Library.Math();

            while ((s = Console.ReadLine()) != null)
            {
                s = Regex.Replace(s, @"\s+", " ");

                string[] numbersString = s.Split(" ");

                foreach (var number in numbersString)
                {
                    double n;
                    bool   success = Double.TryParse(number, out n);

                    if (success)
                    {
                        numbers.Add(n);
                    }
                    else
                    {
                        Console.WriteLine("{0} is not valid number", number);
                        return;
                    }
                }
            }

            foreach (var n in numbers)
            {
                sum = math.Add(sum, n);
            }

            x1 = math.Add(math.Div(1, numbers.Count), sum);

            foreach (var n in numbers)
            {
                double n1 = 0, n2 = 0;

                n1 = math.Pow(n, 2);
                n2 = math.Mul(numbers.Count, math.Pow(x1, 2));

                sum2 = math.Add(sum2, math.Sub(n1, n2));
            }

            double res = math.Sqrt(math.Mul(math.Div(1, math.Sub(numbers.Count, 1)), x1), 2);

            Console.WriteLine(res);
        }
Exemplo n.º 2
0
        private void btn_eq_Click(object sender, RoutedEventArgs e)
        {
            double n2 = 0;

            if (!double.IsNaN(n1))
            {
                try
                {
                    n2 = Double.Parse(input_line.Text.Substring(n1.ToString().Length + 1));
                }
                catch (FormatException)
                {
                    MessageBox.Show("Špatný formát zadaného čísla");
                }
            }

            double o = 0;

            try
            {
                switch (op)
                {
                case 1:
                    o = math.Add(n1, n2);
                    break;

                case 2:
                    o = math.Sub(n1, n2);
                    break;

                case 3:
                    o = math.Mul(n1, n2);
                    break;

                case 4:
                    o = math.Div(n1, n2);
                    break;

                case 5:
                    o = math.Pow(n1, n2);
                    break;

                case 6:
                    o = math.Sqrt(n2, n1);
                    break;
                }
            }
            catch (OverflowException)
            {
                MessageBox.Show("Příliš vysoké číslo");
            }
            catch (DivideByZeroException)
            {
                MessageBox.Show("Nulou nelze dělit");
            }

            op = 0;
            n1 = Double.NaN;
            input_line.Text = o.ToString();
            EnableBinary();
        }