Virtual Threat - 2010
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Calculo polinominal em c#

Ir para baixo

Calculo polinominal em c# Empty Calculo polinominal em c#

Mensagem por brujah999 Qua Nov 11 2009, 16:25

Código:
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Text;
5. 
6. namespace Horner
7. {
8.    class Program
9.    {
10.        //here it all happens
11.        static double Horner(double[] coeffients, int degree, double value)
12.        {
13.            double result = coeffients[degree];
14.            for (int i = degree - 1; i >= 0; i--)
15.            {
16.                result = result * value + coeffients[i];
17.            }
18.            return result;
19.        }
20. 
21. 
22.        //Main function to exercise the above
23.        static void Main(string[] args)
24.        {
25.            //coefficient array
26.            double[] c = {0,0,0,0,0,0,0,0,0,0,0};  //degree 10 maximum
27.            //highest degree
28.            int d;
29.            //value to be evaluated
30.            double v;
31.            Console.WriteLine("HORNER polynomial evaluator.");
32.            Console.WriteLine();
33.            Console.Write("Enter degree of polynomial: ");
34.            d = Convert.ToInt32(Console.ReadLine());
35.            Console.WriteLine("Fill in coefficients from low to high degree.");
36.            Console.WriteLine("Coefficients, a[0], a[1], ..., a[" + d.ToString() + "]");
37.            for (int i = 0; i <= d; i++)
38.            {
39.                Console.Write("Coefficient a[" + i.ToString() + "] = ");
40.                c[i] = Convert.ToDouble(Console.ReadLine());
41.            }
42.            Console.Write("Enter the value to be evaluated: ");
43.            v = Convert.ToDouble(Console.ReadLine());
44. 
45.            double r = Horner(c, d, v);
46.            Console.WriteLine("------------------------------------------------");
47.            Console.WriteLine("The calculated value for this polynomial is : {0}",r);
48. 
49.        }
50.    }
51. }
brujah999
brujah999
Iniciante

Mensagens : 228
Data de inscrição : 14/10/2009
Idade : 42
Localização : São Paulo

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos