Saturday 28 February 2015

Newton forward technique using c programing

#include"neel.h"
float fact(float);
void main()
{
 float x[100],y[100][100],i,j,k,h,xi,s,p;
 int n;
 clrscr();

 printf("enter the total no of variable:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
   printf("enter x[%.0f]:",i);
   scanf("%f",&x[i]);
   printf("enter y[%.0f]:",i);
   scanf("%f",&y[0][i]);
 }
 for(j=0;j<n-1;j++)
 {
   for(k=0;k<n-1;k++)
   {
    if(k<=n-2)
    {
      y[j+1][k] = y[j][k+1] - y[j][k];

    }
   }
 }
 printf("\nenter the unknown x:");
 scanf("%f",&xi);
 s = 0;
 for(j=1;j<=n-1;j++)
 {
    p = 1;
    for(k=1;k<=j;k++)
    {
      p = p*(xi-x[k-1]);
    }
    s = s+ p*y[j][0]/fact(j);
 }
   s = s + y[0][0] ;
   printf("\nresult:%f",s);


getch();
}

float fact(float x)
{
  int p,f=1;
  for(p=x;p>=1;p--)
  f= f*p;
  return f;
}