wrong answer(polynomial)

please take a look at this
find (x-a)*P(x) //P(x) = pnxn + pn-1xn-1 + ... + p0
a, n, p0, p1, ..., pn is given.
Input:
1.5 1
1.5 1
Output:
-2.2 0.0 1.0

here is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<stdio.h>
#define MAX 40
double c,a[MAX],b[MAX],value;
int N,i,j,N1;
int main() {
  scanf("%f",&c);
     scanf("%d",&N);
      for(i=0;i<=N;i++) {
	scanf("%lf",&a[i]);
        }
    N1=N*2+1;
    int max=0;
    for(i=0;i<=N;i++) {
	   value=(a[i]*(-c)+a[i-1]);
	   int pow=(N-i)+(N-i)+2;
	   if(pow>max) max=pow;
	   b[pow]+=value;
           }

    i=max;
    while(i>=2) {
                 printf("%.1f ",b[i]);
          i--;  }
    return 0;
    }

Input:
1.5 1
1.5 1
Output:
-0.0 0.0 1.5
Last edited on
Topic archived. No new replies allowed.