scanf("%d", °);

There is no variable called

`°`

(nor can there be, letters and numbers only are permitted, no symbols).Did you mean

scanf("%d", °);

Following is my program but according the errors

In deriv2 the degree isn't getting saved

Can anyone please tell me what is the error

**What I have tried:**

In deriv2 the degree isn't getting saved

Can anyone please tell me what is the error

#include <stdio.h> #include <conio.h> #include <math.h> float poly(float a[], int, float); float deriv(float a[], int, float); int main() { float x, a[10], y1, dy1; int deg, i; printf("Enter the degree of polynomial equation: "); scanf("%d", °); printf("Ehter the value of x for which the equation is to be evaluated: "); scanf("%f", &x); for (i = 0; i <= deg; i++) { printf("Enter the coefficient of x to the power %d: ", i); scanf("%f", &a[i]); } y1 = poly(a, deg, x); dy1 = deriv(a, deg, x); printf("The value of polynomial equation for the value of x = %.2f is: %.2f", x, y1); printf("\nThe value of the derivative of the polynomial equation at x = %.2f is: %.2f", x, dy1); return 0; } /* function for finding the value of polynomial at some value of x */ float poly(float a[], int deg, float x) { float p; int i; p = a[deg]; for (i = deg; i >= 1; i--) { p = (a[i - 1] + x * p); } return p; } /* function for finding the derivative at some value of x */ float deriv(float a[], int deg, float x) { float d[10], pd = 0, ps; int i; for (i = 0; i <= deg; i++) { ps = pow(x, deg - (i + 1)); d[i] = (deg - i) * a[deg - i] * ps; pd = pd + d[i]; } return pd; } float deriv2(float b[],int deg,float x) float d[10], pd=0, ps; int j,deg2,deg; deg2=deg-1; for (j=deg;j>=0;j--) { if (b[j]>0) c[j]=a[j]*b[j]; b[j]=b[j]-1; else break; } // Running same deriv function and replacing deg with dy2 and a[] with c[] float deriv3(float c[],int deg2,float x) float d[10], pd=0, ps; int k,deg 3; for (k=deg;k>=0;k--) { if (b[k]>0) q[k]=c[k]*b[k]; b[k]=b[k]-1; else break; } deg3=deg2-1; // Running same deriv function and replacing deg3 with dy3 and a[] with q[]

Comments

11917640 Member
21-Jul-22 6:00am

In deriv2 function: int j,deg2,deg; deg2=deg-1; - deg is not initialized. Don't ignore compiler warnings.

Look at your code:

There is no variable called

Did you mean

scanf("%d", °);

There is no variable called

`°`

(nor can there be, letters and numbers only are permitted, no symbols).Did you mean

scanf("%d", °);

Permalink

Share this answer

v2

You really don't need

The derivative of a polynomial is a polynomial as well.

You could just implement a

`deriv2`

and `deriv3`

.The derivative of a polynomial is a polynomial as well.

You could just implement a

`derive_polynomial`

function and call it multiple times.
Permalink

Share this answer

The program cannot be compiled because there are some problems.

This function cannot work like this

The curly brackets are missing from deriv2.

Also, c and a are undefined and curly bracketsare missing.

The deriv3() function is also incomplete.

The loop in the deriv function is repeated 1 time too many, resulting in a negative exponent.

The fact that the result could still be correct is due to multiplication by 0.

This function cannot work like this

C

scanf("%d", °)

The curly brackets are missing from deriv2.

C

float deriv2(float b[], int deg, float x) { ... }

Also, c and a are undefined and curly bracketsare missing.

C

c[j] = a[j] * b[j];

The deriv3() function is also incomplete.

The loop in the deriv function is repeated 1 time too many, resulting in a negative exponent.

C

for (i = 0; i <= deg; i++) { ps = pow(x, deg - (i + 1));

The fact that the result could still be correct is due to multiplication by 0.

Permalink

Share this answer

v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900