Friday, August 22, 2014

C Code for Newton's Forward Difference Interpolation

#include<stdio.h>
#include<math.h>
int main()
{
  float x[25], y[25], ques, ans, a, b, h;
  int i, j , num;

  printf("Enter the Number of elements:");
  scanf("%d",&num);
  printf("Enter the elements of x:");
  for(i=1 ;i<=num; i++)
   {
        scanf("%f",&x[i]);
   }
   printf("Enter the elements of y:");
   for(i=1;i<=num;i++)
   {
    scanf("%f",&y[i]);
   }

  h=x[2]-x[1];
  printf("Enter the value you want to find: ");
  scanf("%f", &ques);
  a=(ques-x[1])/h;
  b=1;
  ans=y[1];

    for(i=1; i<=(num-1); i++)
    {
       for(j=1; j<=(num-i); j++)
        {
              y[j]=y[j+1]-y[j];
        }
        b=b*(a-i+1)/i;
        ans=ans+b*y[1];
    }
   printf("Answer is %6.5f", ans);
   return 0;
}

2 comments:

Compare equality of two string in C

#include <stdio.h> #include<string.h> int main() {     char* country = "Bangladesh";     char* country2;     ...