wap in c to implement newton's forward interpolation formula.

Question-- using newton forward interpolation formula,find the area of a circle of diameter 82 metre                                from the given table of diameter and area of circle.

Diameter(metre)      80          85           90          95            100
Area(metre^2)      5026        5674      6362     7088         7854


code to solve the above question.

#include<stdio.h>
#include<math.h>
main()
{
int i,j,a=0,n;
float x[10],fx[10],delfx[10],result=0,point,f,h,p,fact=1.000;
printf("\nthe point at which u want to calculate the value\n");
scanf("%f",&point);
printf("\nenter the no of elements in x\n");
scanf("%d",&n);

printf("enter the elements of x\n");
for(i=0;i<n;i++)
scanf("%f",&x[i]);

h=fabs(x[0]-x[1]);
p=(point-x[0])/h;
printf("\nthe value of p is %f\n",p);
printf("enter the elements of f(x)\n");
for(i=0;i<n;i++)
scanf("%f",&fx[i]);
f=fx[0];
for(j=n;j>1;j--)
{
for(i=0;i<j-1;i++)
{
fx[i]=fx[i+1]-fx[i];
}
delfx[a]=fx[0];
a++;}
for(i=0;i<a;i++)
{
if(i!=0)
p=p*(p-i);
fact=fact*(i+1);
result=result+(p/fact)*delfx[i];
}
result=result+f;
printf("the result is %f",result);
}


output

wap to implement newton raphson method to find the root of x*sin(x)+cos(x).

#define f(x) x*sin(x)+cos(x)
#define df(x) sin(x)+x*cos(x)-sin(x)
#include<stdio.h>
# include<math.h>
 main()
{
float i,a,b,c;
for(i=0;;i++)
{
if(f(i)>0&&f(i+1)<0)
{
a=i;b=i+1;break;}
if((f(i)<0)&&(f(i+1)>0))
{
a=i+1;b=i;break;}
}
for(i=0;;i++)
{
if(f(b)>0&&df(b)<0)
c=b+(f(b)/fabs(df(b)));
if(f(b)<0&&df(b)>0)
c=b+(fabs(f(b)/df(b)));
if((f(b)>0&&df(b)>0)||(f(b)<0&&df(b)<0))
c=b-(fabs(f(b))/fabs(df(b)));
if(fabs(c-b)<.00001)
break;
b=c;
}
printf("the root is %f",c);
}


Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...