You are on page 1of 45

Page |1

TO IMPLEMENT ITERATIVE METHODS


1. FLOW CHART OF BISECTION METHOD

START

Define F(x)

Get the value of


interval (a,b),
error,iter

Initialize i =1

Call Subroutine bisect mid

Is
B=X F(mid)< A=X
0

Is Abs
(XI- X
X)<Aer
r

I<iter
Y

VIVEK GUPTA Roll no: 0905210064


Page |2

No

Print Solution does


not Converge

Print iter, XI

STOP

Subroutine Bisect

X= (A+B)/2

Iter ++

Print ITER, XI

RETURN

VIVEK GUPTA Roll no: 0905210064


Page |3

2. FLOW CHART OF NEWTON-RAPHSON METHOD

START

Define Function f(x)

Define function df(x)

Get the value of x0,aerr,maxitr

Loop for itr = 1 to maxitr

h = f(x0)/df(x0)

x1 = x0-h

Print itr,x1

No
Is
fabs(h) X0 =x1
<aerr

End loop (itr)


Yes

Print solution Print “solution does


not converge”

STOP
STOP

VIVEK GUPTA Roll no: 0905210064


Page |4

3. FLOW CHART OF REGULA-FALSI METHOD

START

Define Function F(x)

Define function Regulafalsi()

Get the value of x0, x1, aerr, mitr

Initialize itr

Call function regulafalsi with x3, x0, x1, f(x1), f(x0), itr

Yes No
Is
X1 = x2 X0 = x1
f(x0)*f(x1)<0

Call function regulafalsi with x3, x0, x1, f(x1),


f(x0), itr

Yes
Is fabs(x3-
C
x2)<aerr
No

x2 = x3

VIVEK GUPTA Roll no: 0905210064


Page |5

Yes
Is itr < maxitr
B

No

Print “ Not Convergent”

STOP

X = x0-((x1-x0)/(f(x1)-f(x0))*f(x0)

Print itr, x

Return

Print “Solution”

RETURN

VIVEK GUPTA Roll no: 0905210064


Page |6

PROGRAM FOR ITERATIVE METHODS

/* ................TO IMPLEMENT NUMERICAL TECHNIQUES USING SWITCH CASE...........*/

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<string.h>

#include<process.h>

// Declaration of Functions

void bisection();

void regulafalsi();

void raphson();

void main()

int c;

printf("------------************ NUMERICAL TECHNIQUES ************-----------\n\n\n");

printf("\t\t( 1 ). Bisection Method\n");

printf("\t\t( 2 ). Regula Falsi\ Method Of False Position\n\n");

printf("\t\t( 3 ). Newton Raphson Method\n\n");

printf(" Please enter a choice............... : ");

scanf("%d",&c);

switch(c)

case 1:

bisection();

break;

case 2:

VIVEK GUPTA Roll no: 0905210064


Page |7

regulafalsi();

break;

case 3:

raphson();

break;

getch();

// Function Definition

void bisection()

#define EPS 0.00000005

#define F(x) (x)*log10(x)-1.2

//variable declaration field

int count=1,n;

float root=1;

float x0,x1,x2;

float f0,f1,f2;

int i=0;

clrscr();

printf("\n Solution by Bisection Method \n");

printf("\n Equation is ");

printf(" \n\t\t\t (x*log x)-1.2 = 0\n\n");

printf(" Enter the number of iterations : ");

scanf("%d",&n);

/* finding an approximate ROOT of given equatoin, having +ve value*/

for(x2=1;;x2++)

VIVEK GUPTA Roll no: 0905210064


Page |8

f2=F(x2);

if(f2>0)

break;

/*finding an approximate ROOT of given equation, having -ve value*/

for(x1=x2-1;;x2--)

f1=F(x1);

if(f1<0)

break;

//... printing result

printf("\t\t----------------------------------------------------------");

printf("\n\t\t ITERATIONS\t\t ROOTS\n");

printf("\t\t----------------------------------------------------------");

for(;count<=n;count++)

x0=(x1+x2)/2.0;

f0=F(x0);

if(f0==0)

root=x0;

if(f0*f1<0)

VIVEK GUPTA Roll no: 0905210064


Page |9

x2=x0;

else

x1=x0;

f1=f0;

printf("\n\t\t ITERATION %d", count);

printf("\t :\t %f",x0);

if(fabs((x1-x2)/x1)<EPS)

{printf("\n\t\t------------------------------------------------------");

printf("\n\t\t Root = %f",x0);

printf("\n\t\t Iteration = %d\n", count);

printf("\t\t--------------------------------------------------------");

getch();

exit(0);

printf("\n\t\t--------------------------------------------------------");

printf("\n\t\t\t Root = %7.4f",x0);

printf("\n\t\t Iterations = %d\n", count-1);

printf("\t\t----------------------------------------------------------");

getch();

//Function Definition

void regulafalsi()

//... formulae declaration

VIVEK GUPTA Roll no: 0905210064


P a g e | 10

#define EPS 0.00005

#define f(x) 3*x+sin(x)-exp(x);

float f0,f1,f2;

float x0,x1,x2;

int itr;

int i;

clrscr();

printf("\n Solution by FALSE POSITION METHOD\n");

printf("\n\t\t\t Equation is : ");

printf("\n\t\t\t 3*x+sin(x)-exp(x)=0\n\n");

printf(" Enter the number of iterations :");

scanf("%d",&itr);

for(x1=0.0;;)

f1=f(x1);

if(f1>0)

break;

else

x1=x1+0.1;

x0=x1-0.1;

f0=f(x0);

printf("\n\t\t----------------------------------------------------------");

printf("\n\t\t ITERATION\t x2\t\t F(x)\n");

printf("\t\t------------------------------------------------------------");

VIVEK GUPTA Roll no: 0905210064


P a g e | 11

for(i=0;i<itr;i++)

x2=x0-((x1-x0)/(f1-f0))*f0;

f2=f(x2);

if(f0*f2>0)

x1=x2;

f1=f2;

else

x0=x2;

f0=f2;

if(fabs(f2)>EPS)

printf("\n\t\t %d\t%f\t%f\n",i+1,x2,f2);

continue;

printf("\t\t------------------------------------------------------------");

printf("\n\t\t\t\tRoot = %f\n",x2);

printf("\t\t-----------------------------------------------------------");

getch();

//Function definition

void raphson()

//......defining formulae

VIVEK GUPTA Roll no: 0905210064


P a g e | 12

#define f(x) 3*x*x*x-cos(x)-1

#define df(x) 9*x*x+sin(x)

float x1,x0;

float f0,f1;

float df0;

float eps;

float error;

int i=1;

int itr;

clrscr();

printf("\n Sloution by NEWTON RAPHSON method\n");

printf("\n Equation is: ");

printf("\n\t\t\t 3*x-cos(x) - 1 = 0\n\n");

/* Finding an appropriate ROOT of Given Equation, Having +ve value*/

for(x1=0; ;x1+=0.01)

f1=f(x1);

if(f1>0)

break;

/* Finding an appropriate ROOT of Given Equation, Having -ve value*/

x0=x1-0.01;

f0=f(x0);

printf("Enter the number of iterations : ");

scanf(" %d",&itr);

printf("Enter the maximum possible error :");

scanf("%f",&eps);

VIVEK GUPTA Roll no: 0905210064


P a g e | 13

if(fabs(f0)>f1)

printf("\n\t\t The root is near to %.6f\n",x1);

if (f1>fabs(f(x0)))

printf("\n\t\t The root is near to %.6f\n",x0);

x0=(x0+x1)/2;

for(;i<=itr;i++)

f0=f(x0);

df0=df(x0);

x1=x0-(f0/df0);

printf("\n\t\t The %d approximation to the root is : %f",i,x1);

error=fabs(x1-x0);

if(error<eps)

{break;}

x0=x1;

if(error>eps)

{ printf("\n\n\t NOTE :-");

printf(" The number of iterations are not sufficient."); }

printf("\n\n\n\t\t\t-----------------------------------");

printf("\n\t\t\t The root is %.6f ",x1);

printf("\n\t\t\t------------------------------------"); }

--------------------------------------------------------**************************------------------------------------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 14

OUTPUT OF ITERATIVE METHODS

-----------------------************ NUMERICAL TECHNIQUES ************-----------

( 1 ). Bisection Method

( 2 ). Regula Falsi Method Of False Position

( 3 ). Newton Raphson Method

Please enter a choice............... : 1

Solution by Bisection Method

Equation is (x*log x)-1.2 = 0

Enter the number of iterations : 5

----------------------------------------------------------

ITERATIONS ROOTS

----------------------------------------------------------

ITERATION 1 : 2.500000

ITERATION 2 : 2.750000

ITERATION 3 : 2.625000

ITERATION 4 : 2.687500

ITERATION 5 : 2.718750

--------------------------------------------------------

Root = 2.7188

Iterations = 5

----------------------------------------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 15

Solution by FALSE POSITION METHOD

Equation is :

3*x+sin(x)-exp(x)=0

Enter the number of iterations :1

----------------------------------------------------------

ITERATION x2 F(x)

------------------------------------------------------------

1 0.361262 0.002101

------------------------------------------------------------

Root = 0.361262

-----------------------------------------------------------

Solution by NEWTON RAPHSON method

Equation is: 3*x-cos(x) - 1 = 0

Enter the number of iterations : 3

Enter the maximum possible error :.0000001

The root is near to 0.820000

The 1 approximation to the root is : 0.824127

The 2 approximation to the root is : 0.824126

The 3 approximation to the root is : 0.824126

-----------------------------------

The root is 0.824126

------------------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 16

4.FLOW CHART OF NEWTON’S FORWARD INTERPOLATION

START

Input n

Get the values of ax, ay

Get value of x

h = ax[1] – ax[0]

Start loop i = 0 to n-1

Diff.[i][1] = ay[I + 1] – ay[i]

End loop i

Start loop j = 2 to 4

Start loop I = 0 to n - j

Diff[i][j] = diff[I +1][j +1] – diff[i][j – i]

End loop i

End loop j

VIVEK GUPTA Roll no: 0905210064


P a g e | 17

I=0

Is No
B ax[i]>x I=I+1 B

I = i-1

P = (x – ax[i])/h

Y1 = p* diff[I - 1][1]

Y2 = p * (p + 1) * diff[I – 2][2]/2

Y3 = ( p + 2 ) * P * (p -1 )*diff[I – 2][3]/6

Y4 = (p + 2) * (p + 1) * p * (p – 1) * diff[I – 3][4]/24

Ay[i] + y1 + y2 + y3 + y4

Print output x,y

STOP

VIVEK GUPTA Roll no: 0905210064


P a g e | 18

PROGRAM FOR NEWTON’S FORWARD INTERPOLATION


#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<process.h>

#include<string.h>

//...main execution method...

void main()

{// ... variable declaration...

int n,i,j;

float ax[10],ay[10],x,h,p,diff[20][20],y1,y2,y3,y4,y=0;

clrscr();

printf("\n enter the no. of terms -");

scanf("%d",&n);

printf("\n\n enter the value in the form of x -");

for(i=0;i<n;i++)

printf("\n\n enter the value of x%d-",i+1);

scanf("%f",&ax[i]);

printf("\n\n enter the value in the form of y -");

for(i=0;i<n;i++)

printf("\n\n enter the value of y%d-",i+1);

scanf("%f",&ay[i]);

VIVEK GUPTA Roll no: 0905210064


P a g e | 19

printf("\n\n enter the value of x for");

printf("\nwhich you want the value of of y -");

scanf("%f",&x);

h=ax[1]-ax[0];

for(i=0;i<n-1;i++){

diff[i][1]=ay[i+1]-ay[i];}

for(j=2;j<=4;j++)

{for(i=0;i<n-j;i++){

diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

} }

i=0;

do

i++;

}while(ax[i]<x);

i--;

p=(x-ax[i])/h;

y1=p*diff[i-1][1];

y2=p*(p+1)*diff[i-1][2]/2;

y3=p*(p+1)*(p-1)*diff[i-2][3]/6;

y2=(p+2)*(p+1)*p*(p-1)*diff[i-3][4]/24;

y=ay[i]+y1+y2+y3+y4;

printf("\n when x=%6.4f,y=%6.8f",x,y);

printf("\n\n\n press enter to exit");

getch(); }

--------------------------------------*********************-----------------------------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 20

OUTPUT OF NEWTON’S FORWARD INTERPOLATION

enter the no. of terms -3

enter the value in the form of x -

enter the value of x1-1

enter the value of x2-2

enter the value of x3-3

enter the value in the form of y -

enter the value of y1-1.2

enter the value of y2-2.3

enter the value of y3-3.2

enter the value of x for

which you want the value of of y -2.3

when x=2.3000,y=2.62999988

press enter to exit…….


VIVEK GUPTA Roll no: 0905210064
P a g e | 21

5.FLOW CHART OF NEWTON’S BACKWARD INTERPOLATION

START

Input Number of terms n

Get the values of ax, ay

h = ax[1] – ax[0]

Start loop i = 0 to n-1

Diff.[i][1] = ay[I + 1] – ay[i]

End loop i

Start loop j = 2 to 4

Start loop I = 0 to n - j

Diff[i][j] = diff[I +1][j +1] – diff[i][j – i]

End loop i

End loop j

I=0

VIVEK GUPTA Roll no: 0905210064


P a g e | 22

Is ! ax[i] < x
A

I = I +1

A
E

X0 = mx[i]

Sum = 0

Y0 = my[i]

Fun = 1

P = (x – x0)/n

Sum = y0

Start loop k = 1 to 4

Fun = (fun * (p – (k- 1)))/k

Sum = sum + fun * diff[i][k]

End loop k

STOP
VIVEK GUPTA Roll no: 0905210064
P a g e | 23

PROGRAM FOR NEWTON’S BACKWARD INTERPOLATION


#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<process.h>

#include<string.h>

void main()

int n,i,j,k;

float mx[10],my[10],x,x0=0,y0,sum,h,fun,p,diff[20][20],y1,y2,y3,y4;

clrscr();

printf("\n enter the no. of terms -");

scanf("%d",&n);

printf("\n\n enter the value in the form of x -");

for(i=0;i<n;i++)

printf("\n\n enter the value of x%d-",i+1);

scanf("%f",&mx[i]);

printf("\n\n enter the value in the form of y -");

for(i=0;i<n;i++)

printf("\n\n enter the value of y%d-",i+1);

scanf("%f",&my[i]);

printf("\n\n enter the value of x for");

printf("\nwhich you want the value of of y -");


VIVEK GUPTA Roll no: 0905210064
P a g e | 24

scanf("%f",&x);

h=mx[1]-mx[0];

for(i=0;i<n-1;i++)

diff[i][1]=my[i+1]-my[i]; }

for(j=2;j<=4;j++)

for(i=0;i<n-j;i++)

diff[i][j]=diff[i+1][j-1]-diff[i][j-1];

}}

i=0;

while(!mx[i]>x)

{ i++; }

x0=mx[i];

sum=0;

y0=my[i];

fun=1;

p=(x-x0)/h;

sum=y0;

for(k=1;k<=4;k++)

fun=(fun*(p-(k-1))/k);

sum=sum+fun*diff[i][k];

}printf("\n when x=%6.4f,y=%6.8f",x,sum);

printf("\n\n\n press enter to exit");getch();}

--------------------------------------------------**********************-----------------------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 25

OUTPUT OF NEWTON’S BACKWARD INTERPOLATION

enter the no. of terms -3

enter the value in the form of x -

enter the value of x1-1

enter the value of x2-2

enter the value of x3-3

enter the value in the form of y -

enter the value of y1-1.2

enter the value of y2-2.3

enter the value of y3-3.4

enter the value of x for

which you want the value of of y -2.3

when x=2.3000,y=2.62999988

press enter to exit……..

VIVEK GUPTA Roll no: 0905210064


P a g e | 26

6.FLOWCHART OF LAGRANGE’S INTERPOLATION

START

Get the value of n

Get the values ax, ay

Get the value of x

Y=0

Loop for I = 0 to n

Nr = dr = 1

Loop for j to n

Is j ! = i B

Nr* = x – ax[j]

Dr* = ax[i] – ax[j]

B
End loop [j]

Print x, y as solution

STOP

VIVEK GUPTA Roll no: 0905210064


P a g e | 27

PROGRAM FOR LAGRANGE’S INTERPOLATION


#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<process.h>

#include<string.h>

void main()

int n; //...No. of terms

int i,j; //...Loop variables

float ax[100]; //...array limit 99

float ay[100]; //...array limit 99

float x=0; //...User Query

float y=0; //...Initial value 0

float nr; //...calc. section

float dr; //...calc. section

clrscr();

printf("\n Enter the number of terms - ");

scanf("%d",&n);

//... Input Sequel for array X

printf("\n\n Enter the value in the form of x - ");

//...Input loop for X

for(i=0;i<n;i++)

printf("\n\n Enter the value of x%d - ",i+1);

scanf("%f",&ax[i]);

}
VIVEK GUPTA Roll no: 0905210064
P a g e | 28

//...Input Sequel for array Y

printf("\n\n Enter the value in the form of y - ");

//... Input loop for Y

for(i=0;i<n;i++)

{ printf("\n\n Enter the value of y%d - ",i+1);

scanf("%f",&ay[i]); }

//...Inputting the required value query

printf("\n Enter the value of x for ");

printf("\n which you want the value of y - ");

scanf("%f",&x);

for(i=0;i<n;i++)

nr=1;

dr=1;

for(j=0;j<n;j++)

{ if(j!=i)

{ nr=nr*(x-ax[j]);

dr=dr*(ax[i]-ax[j]); }

y+=(nr/dr)*ay[i];

}}

//... Output Section

printf("\n\n When x=%5.2f,y=%5.2f ",x,y);

printf("\n\n\n Press Enter to Exit...");

getch();

//... Termination of Main Execution Thread

------------------------------------------------*****************************------------------------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 29

OUTPUT OF LAGRANGE’S INTERPOLATION

Enter the number of terms - 3

Enter the value in the form of x -

Enter the value of x1 - 1

Enter the value of x2 - 2

Enter the value of x3 - 3

Enter the value in the form of y -

Enter the value of y1 - 1.2

Enter the value of y2 - 2.3

Enter the value of y3 - 4.5

Enter the value of x for

which you want the value of y - 2.3

When x= 2.30,y=13.47

Press Enter to Exit.........

VIVEK GUPTA Roll no: 0905210064


P a g e | 30

7.FLOW CHART OF SIMPSON’S 1/3 RULE

START

Define function y(x)

Get values x0, Xn, n

H = (Xn- x0)/n

S = Y0 + Yn + 4Y1

Loop for I = 3 to n -1

S + = 4 * y1 + 2 * Yi+1

End loop (i)

p = (h/3 ) * s

Print “ solution”, p

STOP

VIVEK GUPTA Roll no: 0905210064


P a g e | 31

PROGRAM FOR SIMPSON’S 1/3 RULE

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<process.h>

#include<string.h>

float fun(float);

void main()

float result=1;

float a,b;

float sum,h;

int i,j,n;

clrscr();

printf("\n\n Enter the range - ");

printf("\n\n Lower Limit a - ");

scanf("%f",&a);

printf("\n\n Upper limit b - ");

scanf("%f",&b);

//... Input No. of Subintervals

printf("\n\n Enter number of subintervals - ");

scanf("%d",&n);

//... Calculation and processing section

h=(b-a)/n;

sum=0;
VIVEK GUPTA Roll no: 0905210064
P a g e | 32

sum=fun(a)+4*fun(a+h)+fun(b);

for(i=3;i<n;i+=2)

sum+=2*fun(a+(i-1)*h)+4*fun(a+i*h);

result=sum*h/3;

//... Output Section

printf("\n\n\n\n Value of integral is %6.4f\t",result);

//...Invoke User Watch halt function

printf("\n\n\n Prress enter to exit");

getch();

//... Termination of Main Execution Thread

//...Function body

float fun(float x)

float temp;

temp=1/(1+(x*x));

return temp;

//...Termination of Function body

------------------------------------*******************************-------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 33

OUTPUT OF SIMPSON’S 1/3 RULE

Enter the range -

Lower Limit a - 2

Upper limit b - 8

Enter number of subintervals - 4

Value of integral is 0.3433

Prress enter to exit……………………………

VIVEK GUPTA Roll no: 0905210064


P a g e | 34

8.FLOW CHART FOR SIMPSON’S 3/8 RULE

START

Define function f(x)

Get values x0, Xn, n

H = (Xn – x0)/n

Sum = 0

Sum = f(a) + f(b)

Loop for I = 1 to n

Is I % 3 Sum + = 2 * f(a + I * h)
=0

Sum + = 3 * f(a + I * h)

End loop i

Print sum

STOP

VIVEK GUPTA Roll no: 0905210064


P a g e | 35

PROGRAM FOR SIMPSON’S 3/8 RULE


#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<string.h>

float fun(float);

void main()

float result=1;

float a,b;

float h,sum;

int i,j,n;

clrscr();

//...Input Range

printf("\n\n Enter the range - ");

printf("\n\n Lower Limit a - ");

scanf("%f",&a);

printf("\n\n Upper Limit b - ");

scanf("%f",&b);

//... Input No.of subintervals

printf("\n\n Enter the number of subintervals - ");

scanf("%f",&n);

//... calculation and processing section

h=(b-a)/n;
VIVEK GUPTA Roll no: 0905210064
P a g e | 36

sum=0;

sum=fun(a)+fun(b);

for(i=0;i<n;i++)

if(i%3==0) {

sum+=2*fun(a+i*h); }

else {

sum+=3*fun(a+(i)*h); }

result=sum*3*h/8;

//... Output Section

printf("\n\n\n\n Value of the integral is %6.4f\t",result);

printf("\n\n\n Press Enter to Exit");

getch();

//...Function body

float fun(float x)

float temp;

temp=1/(1+(x*x));

return temp;

//... Termination Of function body

---------------------------------************************----------------------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 37

9.FLOW CHART OF TRAPEZOIDAL RULE

START

Define function y(x)

Get values x0, Xn, n

H = (Xn- x0)/n

S = y(x0) + y(Xn)

Loop for I = 1 to n -1

S + = 2 * y * (x0 + I * h)

End loop (i)

T = (h/2 ) * s

Print “ solution”, t

STOP

VIVEK GUPTA Roll no: 0905210064


P a g e | 38

PROGRAM FOR TRAPEZOIDAL RULE


#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<process.h>

#include<string.h>

float fun(float);

void main()

float result=1;

float a,b;

float h,sum;

int i,j,n;

clrscr();

//...Input range

printf("\n\n Enter the range - ");

printf("\n\n Lower limit a - ");

scanf("%f",&a);

printf("\n\n Upper Limit b - ");

scanf("%f",&b);

//... Input no. of subintervals

printf("\n\n Enter the number of subintervals - ");

scanf("%d",&n);

//... calculation and processing section

h=(b-a)/n;
VIVEK GUPTA Roll no: 0905210064
P a g e | 39

sum=0;

sum=fun(a)+fun(b);

for(i=1;i<n;i++)

sum+=2*fun(a+i);

result=sum*h/2;

//... Output Section

printf("\n\n\n\n value of the integral is %6.4f\t",result);

printf("\n\n\n Press Enter to Exit....");

getch();

//... Termination of Main Execution thread

//... Function body

float fun(float x)

float temp;

temp=1/(1+(x*x));

return temp;

//...Termination of Function body

-----------------------------***********************----------------------

VIVEK GUPTA Roll no: 0905210064


P a g e | 40

OUTPUT OF TRAPEZOIDAL RULE

Enter the range -

Lower limit a - 2

Upper Limit b - 8

Enter the number of subintervals - 3

value of the integral is 0.5330

Press Enter to Exit................

VIVEK GUPTA Roll no: 0905210064


P a g e | 41

IMPLEMENTATION OF LEAST SQUARE METHOD FOR CURVE


FITTING
#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

Int i=0;

Int observ;

float x[10];

float y[10];

float xy[10];

float x2[10];

float sum1=0.0;

float sum2=0.0;

float sum3=0.0;

float sum4=0.0;

double a;

double b;

clrscr();

printf(“\n\n Enter the number of observations-“);

scanf(“%d”,&observ);

Printf(“\n\n\n Enter the values of x-\n”);

for(;i<observ;i++)

{
VIVEK GUPTA Roll no: 0905210064
P a g e | 42

Printf(“\n\n Enter the value of x%d:”,i+1);

Scanf(“%f”,&x*i+);

Sum1+=x[i];

Printf(“\n\n Enter th values of y-\n”);

for(i=0;i<observ;i++)

Printf(“\n\n Enter the value of y%d:”,i+1);

Scanf(“%f”,&y*i+);

Sum2+=y[i];

for(i=0;i<observ;i++):

xy[i]=x[i]*y[i];

Sum3+=xy[i];

for(i=0;i<observ;i++);

x2[i]=x[i]*x[i];

Sum4+=x2[i];

a=(sum2*sum4-sum3*sum1)/(observ*sum4-sum1*sum1);

b=(sum2-observ*a)/sum1;

printf(“\n\n\n\n Equation of the STRAIGHT LINE “);

printf(“of the form y=a+b*x is:”);

VIVEK GUPTA Roll no: 0905210064


P a g e | 43

printf(“\n\n\n \t\t\t Y=%.2f+(%.2f)X”,a,b);

printf(“\n\n\n Press Enter to Exit”);

getch();

VIVEK GUPTA Roll no: 0905210064


P a g e | 44

VIVEK GUPTA Roll no: 0905210064


P a g e | 45

DRAW FREQUENCY CHART LIKE HISTOGRAM,FREQUENCY CURE


AND PIE CHART ETC.

VIVEK GUPTA Roll no: 0905210064

You might also like