You are here:

- Home
- Computing/Technology
- C/C++
- C
- Re : questions about C

Advertisement

Hi

for example if

x=4

a[x]=1,2,1,5

b[x]=3,2,1,0

j=-4 , k=1

then the polynomial is (x*x*x)+2(x*x)+x+5

and the root between j and k will be -2.4334

I am new to c programming.

I dont know whats wrong with my code.

This program is supposed to find the root of a polynomial

with x being the number of terms (x≤100)

a[x] being the coefficients

b[x] being the power of the variables (must>=0)

j k is any 2 numbers provided that j<k and f(j)*f(k)<0

please help me...thanks...

This is my coding.

#include <stdio.h>

#include <math.h>

int main()

{

int x ;

x<=100;

scanf("%d\n", &x);

double a[x];

int l;

for(l=0; l<x; l++)

{

scanf("%lf", &a[l]);

}

int b[x];

b[x]>=0;

int m;

for(m=0; m<x; m++)

{

scanf("%d", &b[m]);

}

double j,k,c,fj,fk,fc;

j<k;

scanf("%lf %lf",&j,&k);

fj= pow( a[x]*j, b[x]);

fk= pow( a[x]*k, b[x]);

while( fj * fk < 0 )

{

c = (j+k)/2;

fc = pow(a[x]*c, b[x]);

if(fabs( fc ) < 1e-9)

{

break;

}

else if ( fabs( fc )> 0&&fc*fk < 0 )

{

j = c;

}

else if ( fabs( fc )> 0&&fj*fc < 0 )

{

k = c;

}

}

printf("root is %lf\n",c);

return 0;

}

Hi Stephen,

There are a few issues with the code snippet you posted. The lines "x<=100;", "b[x]>=0;", and "j<k;" do not do anything. You have declared a couple arrays of size "x", but a[x], and b[x] are out of bounds. For example if you declare an array "int x[3];", then you would access the array using "x[0], x[1], x[2]". I hope these pointers help you with your program.

I will answer any c language programming and syntax questions.

I have almost a decade of c programming experience.**Education/Credentials**

I have a bachelor of science degree and several years of industry experience.