Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
916 B
1
Indexable
Never
#include <stdio.h>
int main()
{
    int n;
    printf("Enter the data points: ");
    scanf("%d", &n);
    float x[n], y[n], sum = 0,temp,p;
    printf("Enter the value of x : ");
    for (int i = 0; i < n; i++)
    {
        scanf("%f", &x[i]);
    }
    printf("Enter the value of y : ");
    for (int i = 0; i < n; i++)
    {
        scanf("%f", &y[i]);
    }
    printf("Enter the value of x : ");
    scanf("%f",&p);
    printf("\nx\t\ty\n");
    for (int i = 0; i < n; i++)
    {
        printf("%f\t%f\n",x[i],y[i]);
    }
    for (int i = 0; i < n; i++)
    {
        temp = 1;
        for (int j = 0; j < n; j++)
        {
            if (i != j)
            {
                temp =(temp*((p-x[j])/(x[i] - x[j])));
            }
        }
          temp = temp * y[i];
            sum = sum + temp;
    }
    printf("\n Root of the equation: %f",sum);
    return 0;
}
Leave a Comment