MeTOdE LAgRAnGE

/*tgs metnum no3.lagrange*/
#include<stdio.h>
#include<conio.h>

main()
{
    int i,j;
    float x[3],y[3],x0,sum,product;

    clrscr();
    x[0]=1;x[1]=4;x[2]=6;
    y[0]=1.5709;y[1]=1.5727;y[2]=1.5751;
    printf("\nmasukan nilai yang ingin dicari x : ");scanf("%f",&x0);
    sum=0;
    for(i=0;i<3;i++)
      {
        product = y[i];
        for (j=0;j<3;j++)
            if (i!=j)
                product = product * (x0-x[j])/(x[i]-x[j]);
        sum+=product;
      }
    printf("nilai f(%.2f) : %.6f",x0,sum);
    getche();
    return 0;
}

back