Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
#include <stdio.h>
#include <conio.h>
#include <math.h>
float poly(float a[], int, float);
float deriv(float a[], int, float);
float deriv2(float a[], int, float);
float deriv3(float a[], int, float);
int main()
{
float x, a[10], y1, dy1, dy2, dy3;
int deg, i, deg2, deg3;
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);
dy2 = deriv2(a, deg2, x);
dy3 = deriv3(a, deg3, 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);
printf("\nThe value of the derivative of the polynomial equation at x = %.2f is: %.2f", x, dy2);
printf("\nThe value of the derivative of the polynomial equation at x = %.2f is: %.2f", x, dy3);
return 0;
}
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;
}
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 degg, float x)
{
float d[10], pd = 0, ps;
int j, degg, deg;
degg = deg - 1;
for (j = degg; j >= 0; j--) {
if (b[j] > 0)
c[j] = a[j] * b[j];
b[j] = b[j] - 1; else
break; }
float deriv3(float c[], int deggg, float x)
{
float d[10], pd = 0, ps;
int k, deggg;
for (k = deg; k >= 0; k--) {
if (b[k] > 0)
q[k] = c[k] * b[k];
b[k] = b[k] - 1; else
break; }
deggg = degg - 1;
}
Indentation style - Wikipedia[
^]
Best C++ Formatter and Beautifier[
^]
Online C/C++ Formatter, Indenter and Beautifier – Techie Delight[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[
^]