Aman 20151170 2101968: Problem Statement:-Program

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

AMAN 20151170 2101968

Problem Statement:- write a program in c for Newton


forward interpolation method for given table
Program:-
#include<stdio.h>
#include<conio.h>
int main()
{
float x[20], y[20][20];
int i,j, n;
printf("Enter number of data?\n");
scanf("%d", &n);
printf("Enter data:\n");
for(i = 0; i < n ; i++)
{
printf("x[%d]=", i);
scanf("%f", &x[i]);
printf("y[%d]=", i);
scanf("%f", &y[i][0]);
}
for(i = 1; i < n; i++)

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968
{
for(j = 0; j < n-i; j++)
{
y[j][i] = y[j+1][i-1] - y[j][i-1];
}
}
printf("\nFORWARD DIFFERENCE TABLE\n\n");
for(i = 0; i < n; i++)
{
printf("%0.2f", x[i]);
for(j = 0; j < n-i ; j++)
{
printf("\t%0.2f", y[i][j]);
}
printf("\n");
}
return 0;
}

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968
Problem Statement:- write a program in c for Newton
Backward interpolation method for given table
Program:-
#include<stdio.h>
#include<conio.h>
int main()
{
float x[20], y[20][20];
int i,j, n;
printf("Enter number of data?\n");
scanf("%d", &n);
printf("Enter data:\n");
for(i = 0; i < n ; i++)
{
printf("x[%d]=", i);
scanf("%f", &x[i]);
printf("y[%d]=", i);
scanf("%f", &y[i][0]);
}
for(i = 1; i < n; i++)

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968
{
for(j = n-1; j > i-1; j--)
{
y[j][i] = y[j][i-1] - y[j-1][i-1];
}}
printf("\nBACKWARD DIFFERENCE TABLE\n\n");
for(i = 0; i < n; i++)
{
printf("%0.2f", x[i]);
for(j = 0; j <= i ; j++)
{
printf("\t%0.2f", y[i][j]);
}
printf("\n");
}
return 0;
}

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968
Problem Statement:- write a program in c for lagrange
interpolation method by displaying different table for the
given interval
Program:-
#include<stdio.h>
int main()
{
float x[100],y[100],s=1,t=1,k=0,a;
int i,n,j,d=1;
printf("\n enter the number of the terms of the table: ");
scanf("%d",&n);
printf("\n enter the respective values of the variables x and y:");
for(i=0;i<n;i++)
{
scanf("%f",&x[i]);
scanf("%f",&y[i]);
}
printf("\n\n the table you entered is as follows: \n\n");
for(i=0;i<n;i++)
{
printf("%0.3f\t%0.3f",x[i],y[i]);
printf("\n");

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968
}
do
{
printf("\n\n\n enter the value of the x to find the respective value
of y\n\n\n");
scanf("%f",&a);
for(i=0;i<n;i++)
{ s=1;
t=1;
for(j=0;j<n;j++)
{ if(j!=i)
{ s=s*(a-x[j]);
t=t*(x[i]-x[j]); }}
k=k+((s/t)*y[i]);
}
printf("\n\n the respective value of the variable y is: %f",k);
printf("\n\n do you want to continue? press 1 to continue
otherwise press any key to exit= ");
scanf("%f",&d);
} while(d==1);
}

BCA SEMESTER-03 CBNST


AMAN 20151170 2101968

BCA SEMESTER-03 CBNST

You might also like