-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathpolynomial.c
42 lines (30 loc) · 824 Bytes
/
polynomial.c
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <conio.h>
float poly(float a[], int, float);
int main()
{
float x, a[10], y1;
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);
printf("The value of polynomial equation for the value of x = %.2f is: %.2f", x, y1);
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;
}