C Program to Evaluate Polynomial equation


#include <stdio.h>
#include <stdlib.h>
void main()
{
int arr[10];
int i, n, power;
float x, sum;

printf(“Enter Polynomial order : “);
scanf(“%d”, &n);

printf(“Enter the value of X : “);
scanf(“%f”, &x);
printf(“Enter %d coefficients : “, n+1);
for (i = 0; i <= n; i++)
{
scanf(“%d”, &arr[i]);
}
sum = arr[0];
for (i = 1; i <= n; i++)
{
sum = sum * x + arr[i];
}
power = n;

printf(“Given polynomial is: \n”);
for (i = 0; i <= n; i++)
{
if (power < 0)
{
break;
}
if (arr[i] > 0)
printf(” + “);
else if (arr[i] < 0)
printf(” – “);
else
printf(” “);
printf(“%dx^%d “, abs(arr[i]), power–);
}
printf(“\n Sum of the polynomial = %6.2f “,sum);
}

Share this