Monday 21 November 2011

LANGRANGE'S INTERPOLATION PROGRAM IN C

LANGRANGE'S INTERPOLATION PROGRAM IN C



#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
   int n,i,j;
   float x[4],y[4],prod,sum=0,X;

   printf("enter value of n");
   scan("%d",&n);
   printf("enter value of x");
   scan("%f",&X);
   for(i=1;i<=n;i++)
   {
     printf("enter x[%d]",i);
     scanf("%f",&x[i]);
     printf("enter y[%d]",i);
     scanf("%f",&y[i]);
   }
   for(i=1;i<=n;i++)
   {
     prod=1.0;
     for(j=1;j<=n;j++)
     {
       if(i!=j)
       {
        // i!=j;
        prod=prod*(X-x[j])/(x[i]-x[j]);
       }
       sum=sum+y[i]*prod;
     }
     printf("interolated value is : %f",sum);
     getch();
   }
}

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel