Search & Find out

Thursday, December 3, 2009

FORDWARD & BACKWARD DIFFERENCE TABLE

#include "stdio.h"
#include "conio.h"
#include "math.h"


void main()
{
  int o,i,n,m,q,j,p,k[100],z;
  float x1,x[100],fx[100],f[100],ffx,s,s1,ss[100],l[100];
  clrscr();

  printf("Welcome to the Forward & Backward Difference Tables\n\n");
  printf("Your option plzzzzzzzz\n\n");
  printf("\n\t1) Forward\t2)Backward\n\n");
  cin>>o;

  if(o!=1 && o!=2)
  {
    printf("Invalid option\nTry again\n");
    goto exit;
  }

  printf("Enter the no. of x's do you wish to give\t");
  cin>>n;
  q=n;

  for(i=1;i<=n;i++)
  {
    printf("Enter the value of x%d\t",i);
    cin>>x[i];
    printf("Enter the value of f(x%d)\t",i);
    cin>>fx[i];
    printf("\n");
  }

  for(i=1;i
  {
    l[i]=x[i+1]-x[i];

    if(i>1 && (l[i-1]!=l[i]))
    {
      printf("The program can't be perform further, b.coz the intervals are different\nbye\n");
    goto exit;
    }
   }

  printf("\nEnter the value of x to find f(x)\n");
  cin>>x1;


  if(o==1)
  {
    s=((x1-x[1])/l[1]);
    ffx=fx[1];

  }
  else
  {
   s=((x1-x[n])/l[1]);
   ffx=fx[n];
  }

  s1=s;
  ss[1]=s;

  for(i=1,k[0]=1;i
  {
   if(o==1)
   ss[i+1]=(s*(s1-i));

   else
   ss[i+1]=(s*(s1+i));

   s=ss[i+1];

   k[i]=(i*k[i-1]);
  }


  for( j=1;  p!=z && j
  {

      for(i=1;i
      {
     f[i]=fx[i+1]-fx[i];
     fx[i]=f[i];

     printf("%f\t",fx[i]);
      }

      printf("\n");

      if(o==1)
      {
    ffx=((ss[j]*fx[1])/k[j]) + ffx;

      }
      else
      {
    ffx=((ss[j]*f[i-1])/k[j]) + ffx;
      }

      m=q-1;

      for(i=1,p=0;i
      {
    l[i]=fx[i+1]-fx[i];

    if(l[i]==0)
    p=p+1;
      }

      z=m-1;
    }
     printf("%f",ffx);

exit:

   getch();

  }



Download the executable (.exe)  file for this program..
download

0 comments:

Post a Comment

 

My Blog List

Term of Use