polynomial - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

polynomial

makkamakka Posts: 1Member
Hello,

I'm having a problem to write a polynom in pascal.

I want to use a array.
E.g. consider a polynoom y = a + bx + cx2 + dx3 , then we can store a, b, c and d in array.
I have to write a program where I get the value of y as x runs of - 1 up to 1 with steps of 0.1.
The user must fill a polynoom of the tenth degree or lower.
Care for a beautiful output.

Comments

  • evangozalievangozali Posts: 4Member
    How about:
    [code]var arr: array[0..10] of real;
    n, i, j: integer; y: real; x: real;
    begin
    read(n); //the maximum degree of the polynom
    for i:= 0 to n do
    read(arr[i]);
    for i:= -10 to 10 do begin
    x:= i/10;
    y:= arr[n];
    for j:= n-1 downto 0 do begin
    y:= y * x;
    y:= y + arr[j];
    end;
    writeln('x = ',x:0:1,' y = ',y:0:1);
    end;
    end.[/code]
    Here I use the i-th array to store the coefficient of x^i.
    CMIIW.
Sign In or Register to comment.