15,921,660 members
1.00/5 (1 vote)
See more:
Following is the program I have made to calculate 3 derivates of a 3 degree polynomial function at a point x

What I have tried:

```#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, j;

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;
}

//take co-eff values through scanf command use for loop

for (i=deg;i>0;i--)
{
scanf("%d",&a[i]);
b[i]=i;
}
for (j=deg;j>=0;j--)
{
if b[j]>0
c[j]=a[j]*b[j];
b[j]=b[j]-1;
}
printf("%dx^%d",&c[j],&b[j]);
}
else
}
deg=deg-1;
//Second derivative
for(k=deg;k>0;k--)
{
if b[k]>0;
{
c[k]=c[k]*b[k];
b[k]=b[k]-1;
printf("%dx^%d",&c[k],&b[k]);
}
else

deg=deg-1;
}
//Third derivative
for (l=deg;l>0;l--)
{
if b[l]>0;
{
c[l]=c[l]*b[l];
b[l]=b[l]-1;
printf("%dx^%d",&c[l],&b[l]);
}
else
}
return 0;```
Posted
Updated 20-Jul-22 21:41pm

## Solution 1

You didn't write the `deriv` function.
It is not difficult, knowing that, for the derivative polynomial
`a[k] = a[k+1]*(k+1)`
where
`k = 0,1,..(deg-1)`

## Solution 2

All functions need a header, an open curly bracket, and a close curly bracket:
C
```ReturnType FunctionName(ParameterList)
{
... body of function here ...
}```

Your code is missing those and you cannot just put code in the file randomly - C only allows code inside functions!

You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword; sometimes we forget to close a string or a code block. Sometimes the cat walks over your keyboard and types something really weird. Sometimes we just forget how many parameters a method call needs.

We all make mistakes.

And because we all do it, we all have to fix syntax errors - and it's a lot quicker to learn how and fix them yourself than to wait for someone else to fix them for you! So invest a little time in learning how to read error messages, and how to interpret your code as written in the light of what the compiler is telling you is wrong - it really is trying to be helpful!

So read this: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^] - it should help you next time you get a compilation error!