C - Program
C - Program
tinclude<stdio.h>
#incdude<conio.h>
tinclude<math.h>
tdefine FUN(x) 3*x-cos(x)-1 / Given
equation /
#define DFUN(x) 3+sin(x) / First derivative of the given equation "/
VOId main()
int in
float x0.x1.x2:
doublee:
drscr):
printf("in **Newton-Raphson Method ***;
pintf("inGive the starting value for iteration (x0):");
scanf("f. &x0):
printf(n Value of the root to how many significant decimal
scanf("%d. &n): places? i.e. n=");
=0:
e= 1/(pow( 10.n));
pintf("n e value = %If", e);
begin:
x1=x0{FUN(X0)/(DFUN(X0):
printf("n Iteration No. i=%d:The value of
f (fabs((x1-x0)/x1) >= e) approximate root (x0)=%f ", i,x0);
0 = x1:
i=i+1:
goto begin:
printf("n The real positive root of the given equation = %f", x1);
2=x0-4FUN(X0)/(DFUN(X0):
f (2-x1 ==0.0)
printf("n The root Converged.");:
else
printf("n The root does not converge. Try with different e value.");
getchl):
rC program: Trapezoidal rule I
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define F(X) 1/(1+pow(X,2))
void main()
{
int n,i;
float a,b,SUM,trap,h,X;
clrscr().
printf(" *****TRAPEZOIDAL RULE*****n"):;
printf("\n Enter the values of a, b, n:");
scanf("%f %f %d", &a, &b, &n);
h=(b-a)/n;
SUM=0.0:
for(i=1;i<=n-1;it+)
{
X={a+ih):
SUM=SUM+F(X);
trap=h/(2.0°(F(a)+
printf("n Value of
F(b)+2.0* SUM);
the given integral= %f", trap):
getch():
C program: Simpson's (1/3)rule /
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define F(*) 1/(1+ pow(x, 2))
float a, b, h, sum, os, es, val, x;
void main()
{
int n, i;
clrscr():
printf("Simpson's (1/3) Rule");
printf("n Give lower limit of the integral (a)=");:
scanf("%f",&a);
printf("n Give upper limit of the integral (b)=");
scanf("%f",&b);
printf("n Give number of intervals (n)[should be even number]=");
scanf("%d", &n);
h=(b-a)/n;
sum=es=0s=0.0;
sum=F(a)+F(b);
for(i=1;i<=n-1;i=i+2)
os=0s+F(a+ih);
for(i=2;i<=n-2;i=i+2)
es=es+F(a+i'h);
val=(h/3.0)°(sum+(4"os)+(2*es));
%f \n", a, b);
printf("\n The value of the integral between limits %f and
val);
printf("n with class interval (h)=%f is equal to %fn", h,
getch();
#include<stdio.h>
main()
Void
Scanf("%ed",&n);
for(i=0;1<=n-1;1++)printt("n
Enter
the printt("\n
pr1nt("\n include C-Program
clrscr(): float#include<conio.h
a,n,i;int <math.h>
=n-1;1++)
for(i=0;i< printf("\n
for(i=0;i<=n-1;i++)
print("\n\nThe Sumx=Sumx
sumy=sumy
sumx2=sumx2 +x[):
+x[)*x[0):; scanf("%f,&y[i]); scanf("
%f°
sumx*sumx)1.0);
a=((sumx2*sumy
getch(): Sumxy=sumxy
+x[)*y[0):
b=((n a,b,x(20),.y[20),sumx=0,sumy=0,sumxy=0,sumx2=0;
Enter Enter C for
xy-sumx*sumy)* &x(i]): program Linear
the the
+y[]:
line values values
x:*);ofvalue Cuve
for
is Linear
of
Y=%3.3f of Fitting
number
y:");
Curve LEAST
2-sumx*sumx)*
+%3.3f of
Fitting
data SQUARES
terms of
X",a,b);
the
n:");form METHOD
Y
=
a /
1.0); +
bx
\n
");
voidfloat
#include<math.h>
#include<stdio. h>
x0,y0,xn,h:");
printf("\n\nx\t\ty\n");printf("Enter
X=X0;
printf("Runge
y=y0;
Scanf("%f%f drscr();float
float
k2=%fAtk3=%f\tk4=%f\n",k1,
foat k; k4 k3while(x<xn)
k2kl main()
dydx(float Runge
=(x+y): getch():
eturn k:printf("%f\t%f\n"x,y):
= === k3,k4,k,y,X,h,xn;
x0,y0,k1,k2,
dydx(float h*dydx((x
h*dydx((x
h*dydx(x,
h*dydx((x
X=X+h;
y=y+k;
k=((k1+2*k2+2*k3+k4)*1.0/6.0); Kutta
/* Kutta x,
input float Method
x,float + %f",&x0,&y0,&xn,&h);
+ +y);
0.5*h),
h),0.5*h), method y);
the
(y -
R.H.S. y) Fourth
+
+0.5*k1));
k3)); (y (y \n");
of + order
0.5*k2));
the
formula
erentlal
quatlon k2,
k3,
k4);
/
Include<stdlib.h>
main()
vold
Inudeestdio.h»
tincudes
malh.h>
printf("ute* printf("
printf("N printt("\ printf("Enter
number
sranf("%d",
forlprint" pnntr
Scanf("%d",the
printfi"Enter
&ni): &ne): drscr(); foat loat int
for(ie1jespe;e+)
ner<nnt
(iter1;
itere+) print("). lor(in1;
les
nne; n printf(My
e) for
printf(\):
Jene+1;j++)
forlj=; , (onio.hude Poyam
forj1;
ene,
je+) for(l-1;
lkene;++)0.0,big else ne+1)ifg s a1o)[ e, ,
M(ra>big) Gven scanf("%,
&a]): () 1; Ae):
"%r
bigre,
umnal d+alL
print( D:elee print(
alt): r, Enter re, nl,
ternp)e
gfgbel( constant
I<ne;
tonp, GAUSS-SEIDEL 1; 10), big, ne, to
Md.D. Equatons j the
the ter; solve
GAUSS-SEIDEL temp,
<=ne+ x{
i++) error\n");:
coetficients allowed number 10):
values the
n). 1; sum; given
METHOD j++) of teratlons
n"; of of
the equations equatlos
of
equations x,
":
y.
z \n"):
and usiny
\n"); the
Gauss
n";
Seidel
Metthod/
getch();
forfi= f(bige)
>
printf("x(%d)=%f\n",
X(Ü): ,printf("\n
1;
i<
Solution
=ne;
i++)
\n"); :
<math.h>
#includeINTERPOLATION
main()
#include<conio.h> void LAGRANGES
METHOD/
eC-Program to
#include<stdio.h>
for(i=1;i<=n;i++)
scanf("%d",&n);
scanf("%f%f",&x(i),printf("\n
&y(i));
printf("\nGive cdrscr():
printf("\n\t i,j,n;
x[20],y[20],z[20),
s=0.0,t=0.0,a,p; intfRloat
#include<stdlib.h>
nti(\n\nFor
getch0:x=%fthe ) zl0=0.0;
forj=1;j<=nj++) p=1.0;
foof",
tt+e*yl. $=p, M(l=i)
pp"(axqD/(«-xi): Ken;i++) printf("Give
",&a); Give
*** interpolate
the the
the
value valuesLAGRANGE'S
interpolated ofx number the
of
for x value
and
INTERPOLATION of
value which values of
y
from a
of interpolation function
y=%/a,): the in
the
table from
tabulated
METHOD
is \n"); a
to set
be ***\n");
data:"); of
found:"); values
using