Upload
husnain-a-ali
View
221
Download
0
Embed Size (px)
Citation preview
8/8/2019 Copy of 38 Programsmm
1/49
Program no.1
Write a program in C to find sum and average of square offirst 100 natural numbers.
/* PROGRAM TO CALCULATE SUM AND AVERAGE OF 100 NATURALNUMBERS*/
#include
#include
#include
void main( )
{
int i, n=100,sum=0, p;
float avg;
for (i=1;i
8/8/2019 Copy of 38 Programsmm
2/49
i=i+1;
prod=prod*i;
if(i
8/8/2019 Copy of 38 Programsmm
3/49
OUTPUT:
Principal amount p =5000
Rate of interest r =10
Time period t =12
Simple Interest = 6000.000000
Compound Interest = 10692.14188
Program no 4
/* FIBBONACCI SERIES */
#include#include
#include
void main()
{
clrscr();
int i;
double x1,x2,x;
x1=1;
x2=1;
printf("%12.0f\t%12.0f",x1,x2);
for(i=3;i
8/8/2019 Copy of 38 Programsmm
4/49
Program no.5
/*GENERATING PRIME NO. BETWEEN 1 AND 100*/
#include
#include
#include
void main()
{
int i,j,count=0;
clrscr();
printf("\nprime nos. between 1 and 100\n");
for(i=1;i
8/8/2019 Copy of 38 Programsmm
5/49
31 37 41 43 47
53 59 61 67 71
73 79 83 89 97
Program no.6Write a program in C to generate prime nos. between 1 and
100 exceptthose divisible by 5.
/* GENERATE PRIME NOS. BETWEEN 1 AND 100 EXCEPT THOSEDIVISIBLE BY 5*/
#include
#include
void main()
{
clrscr();
int n1=1,n2=100,j,i,temp,k=0,flag=0;
for (i=n1;i
8/8/2019 Copy of 38 Programsmm
6/49
flag=0;
break;
}
}
if (flag==1)
{
printf ("\t %d",temp);
}
}
}
OUTPUT:
2 3 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67
71 73 79 83 89 97
Program no. 7
/* to sort a list of 5 numbers in ascending order*/
#includeD#include
#includevoid main()
{
int i,j,t;
int n[5]; clrscr();
//to enter the data
printf("\n enter the 5 numbers to be sorted\n");
for(i=0;i
8/8/2019 Copy of 38 Programsmm
7/49
printf("output:");
for(i=0;i
8/8/2019 Copy of 38 Programsmm
8/49
else
{
for(j=1;j
8/8/2019 Copy of 38 Programsmm
9/49
enter any number == 2319
sum of digit given number == 15
Program no. 10/*CALCULATION OF TAXABLE INCOME*/
#include
#include
#include
void main()
{
float income,tax;clrscr();
printf("\nenter taxable income:");
scanf("%f",&income);
if(income
8/8/2019 Copy of 38 Programsmm
10/49
amount of tax on Rs132000.000000 equals to
Rs32600.000program no. 11
/* CALCULATION OF SINE SERIES */
#include
#include
#include
int fact (int a);
void main()
{
double x,sum1=0.0,sum2=0.0,sum=0.0;
int y,i;
clrscr();
printf("\nenter the value for x:");
scanf("%lf",&x);
for(i=1;i
8/8/2019 Copy of 38 Programsmm
11/49
enter the value for x:1
sum of sine series sin(1.000000)==0.841471
Program no 12
/*CALCULATION OF COSINE SERIES*/
#include
#include
#include
long fact (int a);
void main()
{
double x,sum1=0.0,sum2=0.0,sum=0.0;
int y,i;
clrscr();printf("\nenter the value for x:");
scanf("%lf",&x);
for(i=0;i
8/8/2019 Copy of 38 Programsmm
12/49
Program no.13
Write a program in C to find out the average marks ofstudents and print the marks of the topper.
/* PROGRAM TO FIND OUT AVERAGE MARKS OF STUDENTS */
#include
#include
#include
void main()
{
int stu[20][20],i,j,m,n,roll=0;
float avg[20],sum=0.0,max=0.0;
clrscr();
printf("\n Enter the number of students =");
scanf("%d",&n);printf ("\n Enter the number of subjects =");
scanf ("%d",&m);
for(i=1;i
8/8/2019 Copy of 38 Programsmm
13/49
average =%f",roll,max);
getch();
}
OUTPUT:
Enter the number of students =3
Enter the number of subjects =5
Enter marks for 1 student
Subject 1=69
Subject 2=58
Subject 3=45
Subject 4=10
Subject 5=35
Enter marks for 2 student
Subject 1=47
Subject 2=25
Subject 3=16
Subject 4=97
Subject 5=46
Enter marks for 3 studentSubject 1=30
Subject 2=90
Subject 3=76
Subject 4=58
Subject 5=47
The average of the 1 student = 42.400002
The average of the 2 student = 45.200001
The average of the 3 student = 59.200001
The topper of the class is student 3 with average =
59.200001
Program no.14
Write a program in C to reverse the digits of a number andfind the sum of its digits.
/* PROGRAM TO REVERSE THE DIGITS OF A NUMBER AND FIND THE
8/8/2019 Copy of 38 Programsmm
14/49
SUM OF ITS DIGITS */
#include
#include
void main()
{
int n1,n2=0,rem,sum=0;
printf ("\n Enter the number to be reversed=");
scanf ("%d",&n1);
while (n1>0)
{r
rem=n1%10;
n1=n1/10;
n2=n2*10+rem;
}
printf ("\n The reversed number is %d",n2);
while (n2>0)
{rem=n2%10;
n2=n2/10;
sum=sum+rem;
}
printf ("\n The sum of digits of reversed number is
%d",sum);
}
OUTPUT:
Enter the number to be reversed =4567
The reversed number is 7654
The sum of digits of reversed number is 22
Programme no. 15Write a program in C to find the sum, mean standard deviation
andvariance of any numbers.
/*......STANDARD DEVIATION AND VARIATION ........*/
#include
#include
#include
void main()
{
clrscr();
int n;
8/8/2019 Copy of 38 Programsmm
15/49
float x[20],sum;
float am,var,sd;
int i;
printf("\n enter the no. of terms=");
scanf("%d",&n);
printf("\n enter %d values \n",n);
for(i=0;i
8/8/2019 Copy of 38 Programsmm
16/49
{
int num[10];
int i,x=2,j,y=0,n;
printf ("\n Enter the number of elements of binary
number=");
scanf ("%d",&n);
j=n-1;
for (i=0;i=0)
{
for (i=0;i
8/8/2019 Copy of 38 Programsmm
17/49
int i=0,j,n;
int rem[10];
printf ("\n Enter the number=");
scanf ("%d",&n);
do
{
rem[i]=n%2;
i=i+1;
n=n/2;
}
while (n>0);
for (j=i-1;j>=0;j--)
{
printf ("The binary number is %d",rem[j]);
}
}
OUTPUT:
Enter the number= 123
The binary number is 1111011
program no.18Write a program in C to add two rectangular matrices.
/* ADDTION OF MATRIX */
#include
#include
void main(){
int mat1[10][10],mat2[10][10],mat3[10][10];
int i,j,m,n;
clrscr();
printf ("\n The number of rows are=");
scanf ("%d",&m);
printf ("\n The number of columns are=");
scanf ("%d",&n);
for (i=0;i
8/8/2019 Copy of 38 Programsmm
18/49
for (j=0;j
8/8/2019 Copy of 38 Programsmm
19/49
6 8
10 12
Program no. 19
/*MULTIPLICATION OF MATRIX*/
#include
#include
void main()
{int m,n,p,q,i,j,k;
int a[10][10],b[10][10],c[10][10];
clrscr();
printf("\nenter no. of row and col of matrix a:");
scanf("%d%d",&m,&n);
printf("\nenter no. of row and col of matrix b:");
scanf("%d%d",&p,&q);if(n!=p)
{
printf("\nmatrix can't be multiplied\n");
goto end;
}
printf("\nenter matrix a\n");
for(i=0;i
8/8/2019 Copy of 38 Programsmm
20/49
}
output:
enter no. of row and col of matrix a:3 3
enter no. of row and col of matrix b:3 2
enter matrix a
0 1 2
1 2 3
2 3 4
enter matrix b
1 -2
-1 0
2 -1
the product ofmatrix is:
3 -25 -5
7 -8
program no.20
/*BISECTION METHOD*/#include
#include
#include
void main()
{ float fun(float m);
float x1,x2,x3,p,q,r;
int i=0;
clrscr();
l10: printf("\nequation:x*(exp(x)-1) ");
printf("\nenter the app value of x1,x2:");
\scanf("%f %f",&x1,&x2);if(fun(x1)*fun(x2)>0)
{ printf("\n wrong values entered...enter again:\n");
goto l10;}
else
printf("\n the root lies b/w %f & %f",x1,x2);
printf("\n n x1 x2 x3 f(x1)
f(x2) f(x3)");
8/8/2019 Copy of 38 Programsmm
21/49
l15: x3=(x1+x2)/2;
p=fun(x1);
q=fun(x2);
r=fun(x3);
i=i++;
printf("\n%d %f %f %f %f %f
%f",i,x1,x2,x3,p,q,r);
if((p*r)>0)
x1=x3;
else
x2=x3;
if((fabs((x2-x1)/x2))
8/8/2019 Copy of 38 Programsmm
22/49
the root lies b/w 0.500000 & 1.000000
n x1 x2 x3 f(x1) f(x2)
f(x3)
1 0.500000 1.000000 0.750000 -0.175639
1.718282 0.587750
2 0.500000 0.750000 0.625000 -0.175639
0.587750 0.167654
3 0.500000 0.625000 0.562500 -0.175639
0.167654 -0.012782
4 0.562500 0.625000 0.593750 -0.012782
0.167654 0.075142
5 0.562500 0.593750 0.578125 -0.012782
0.075142 0.030619
6 0.562500 0.578125 0.570312 -0.012782
0.030619 0.008780
7 0.562500 0.570312 0.566406 -0.012782
0.008780 -0.002035
8 0.566406 0.570312 0.568359 -0.0020350.008780 0.003364
9 0.566406 0.568359 0.567383 -0.002035
0.003364 0.000662
10 0.566406 0.567383 0.566895 -0.002035
0.000662 -0.000687
root of the equ is 0.566895
programme no 21
/*NEWTON RALPHSON*/#include
#include
#include
void main()
{
float f(float a);
float df(float a);
int i=1;
float x0,x1,p,q;
float error =0.0001,delta =0.001;
clrscr();printf("\n\nThe equation is X^3+1.2X^2-5X-7.2");
printf("\nenter the initial value of x0:");
scanf("%f",&x0);
printf("\n i x0 x1 f(x0)
df(x0)\n ");
if (fabs (df(x0))
8/8/2019 Copy of 38 Programsmm
23/49
a10: else p=f(x0);q=df(x0);
x1=x0-(p/q);
i++;
printf("\n %d\t%f\t%f\t%f\t%f\n",i,x0,x1,p,q);
if(fabs((x1-x0)/x1)
8/8/2019 Copy of 38 Programsmm
24/49
Programme no.22 /*REGULA-FALSE METHOD */
#include
#include
#include
float f(float x)
{return(3*x-cos(x)-1);
}
void main()
{ float f(float x);
double x1,x2,m;
int c=0;
clrscr();
b printf("\n enter the first approximation :");
scanf("%f",&x1);printf("\n enter the second approximation :");
scanf("%f",&x2);
if(f(x1)*f(x2)=0.0001)
{
c++;
if(f(x1)*f(m)
8/8/2019 Copy of 38 Programsmm
25/49
The 1,ilteration is 0.605959
The 2,ilteration is 0.607057
The 3,ilteration is 0.607100
The answer is repeated at 3 ilteration is 0.607100
Program no.23
/*NEWTON GREGORY FORWARD INTERPOLATION*/
#include
#include
#includevoid main()
{
int n,i,j,k;
float mx[10],my[10],x,y=0,h,p,diff[20][20],y1,y2,y3,y4;
clrscr();
printf("\nenter no. of terms:");
scanf("%d",&n);
printf("\nenter values x\ty:\n");
for(i=0;i
8/8/2019 Copy of 38 Programsmm
26/49
y=my[i]+y1+y2+y3+y4;
printf("\nwhen x=%6.4f,y=%6.8f",x,y);
getch();
}
OUTPUT:
enter no. of terms:5
enter values x y:3 13
5 23
11 899
27 17315
34 35606
enter value of x at which y is to be calculated:7
when x=7.0000,y=899.00000000
Program no.24
/*NEWTON GREGORY BACKWARD INTERPOLATION*/#include
#include
8/8/2019 Copy of 38 Programsmm
27/49
#include
void main()
{
int n,i,j,k;
float mx[10],my[10],x,x0=0,y0,sum=0,fun=1,h,p,diff[20]
[20],y1,y2,y3,y4;
clrscr();
printf("\nenter no. of terms:");
scanf("%d",&n);
printf("\nenter values x\ty:\n");
for(i=0;i
8/8/2019 Copy of 38 Programsmm
28/49
20 41
40 103
60 168
80 218
100 235
enter value of x at which y is to be calculated:70
when x=70.0000,y=196.00000000
program no.25
/*LAGRANGE METHOD OF INTERPOLATION*/
#include
#include
#include#define max 50
void main()
{
float ax[max],ay[max],nr,dr,x,y=0;
int i,j,n;
clrscr();
printf("\nEnter No. of Points:");
scanf("%d",&n);
printf("\nEnter the given set of values:\nx\ty\n");
for(i=0;i
8/8/2019 Copy of 38 Programsmm
29/49
Enter No. of Points:6
Enter the given set of values:
x y
4 18
5 100
7 294
10 900
11 1210
13 2028
Enter the value of x at which f(x)is required:8
when x= 8.00 then y=445.62
Programme no.26Write a program in C/C++ which can calculate the value of afunction at a point using Newton Divided Difference method.
/* NEWTON DIVIDED DIFFERENCE METHOD */
#include
#include
#includevoid main()
{
float ax[20], ay[20], diff[30],temp=1;
int n,j,m,z=0,A=0,k=0;
clrscr();
coutn;
for (int i=0;i
8/8/2019 Copy of 38 Programsmm
30/49
// creating difference table
for (i=0;i1)
{
m=n-1;
A=0;
for(j=0;j
8/8/2019 Copy of 38 Programsmm
31/49
OUTPUT:
Enter the number of points=5
Enter (x1 ,y1 ) 5 150
Enter (x2 ,y2 ) 7 392
Enter (x3 ,y3 ) 11 1452
Enter (x4 ,y4 ) 13 2366
Enter (x5 ,y5 ) 17 5202
Enter the value of x=9
The difference table is as follows:
121
265
457
709
24
3242
1
1
0
The value of y for x = 9 is: 810
Program no.27
/******BESSEL'S METHOD OF INTERPOLATION******/#include
#include
#include
void main()
{ int n , i , j ;
float ax[10] , ay[10] , x , y=0 , h , p , diff[20][20]
, y1 , y2 , y3 , y4 ;
clrscr();
printf("\nEnter the noumber of item : ");
scanf("%d" , &n);printf("\nEnter the value in the form of x\n");
for(i = 0 ; i < n ; i++)
{ printf("\nEnter the value of x%d\t" , i+1);
scanf("%f" , &ax[i]); }
printf("\nEnter the value in the form of y\n");
for(i = 0 ; i < n ; i++)
{ printf("\nEnter the value of y%d\t" , i+1);
8/8/2019 Copy of 38 Programsmm
32/49
scanf("%f" , &ay[i]); }
printf("\nEnter the value of x for which you want the
value 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
8/8/2019 Copy of 38 Programsmm
33/49
Programe no 28
/******STIRLING METHOD OF INTERPOLATION******/#include
#include
#include
void main()
{ int n , i , j ;
float ax[10] , ay[10] , x , y=0 , h , p , diff[20][20] ,
y1 , y2 , y3 ,y4;
8/8/2019 Copy of 38 Programsmm
34/49
clrscr();
printf("\nEnter the noumber of item : ");
scanf("%d" , &n);
printf("\nEnter the value in the form of x\n");
for(i = 0 ; i < n ; i++)
{printf("\nEnter the value of x%d\t" , i+1);
scanf("%f" , &ax[i]); }
printf("\nEnter the value in the form of y\n");
for(i = 0 ; i < n ; i++)
{printf("\nEnter the value of y%d\t" , i+1);
scanf("%f" , &ay[i]); }
printf("\nEnter the value of x for which you want the
value 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
8/8/2019 Copy of 38 Programsmm
35/49
OUTPUT :Enter the number of item : 4
Enter the value in the form of x
Enter the value of x1 20
Enter the value of x2 24
Enter the value of x3 28
Enter the value of x4 32
Enter the value in the form of y
Enter the value of y1 24
Enter the value of y2 32
Enter the value of y3 35
Enter the value of y4 40
Enter the value of x for which you want the value of y
:- 25
When x = 25.0000 , y = 33.31251144
Program no.29
/* TRAPEZOIDAL RULE */
#include#include
#include
void main()
{
float fun(float);
float h , k1=0.0 ;
float x[20] , y[20];
int n , i;
clrscr();
printf("\nEnter number of parts : ");
scanf("%d" , &n);
printf("\nEnter lower and upper limits : ");
scanf("%f %f" , &x[0] , &x[n]);
y[0] = fun(x[0]);
h = (x[n] - x[0])/n ;
8/8/2019 Copy of 38 Programsmm
36/49
printf("\nx y");
printf("\n %8.5f %8.5f " , x[0] ,y[0]);
for(i=1 ; i < n ; i++)
{ x[i] = x[0] + i * h ;
y[i] = fun(x[i]);
printf("\n %8.5f %8.5f " , x[i] , y[i]);
k1 = k1 + 2 * y[i];
}
y[n] = fun(x[n]);
printf("\n %8.5f %8.5f " , x[n] , y[n]);
y[0] = (h / 2.0 ) * (y[0] + y[n] + k1 );
printf("\nresult = %f \n" , y[0]);
getch();
}
float fun(float x)
{
float g;g = log(x);
return g;
}
OUTPUT :-Enter number of parts : 6
lower and upper limits : 4 5.2
x y
4.00000 1.38629
4.24000 1.44456
4.48000 1.499624.72000 1.55181
4.96000 1.60141
5.20000 1.64866
result = 1.827570
program no.30
/* SIMPSION 1/3 RULE */
#include#include
#include
void main()
{ float fun(float);
float h , k1=0.0 , k2=0.0 ;
float x[20] , y[20];
int n , i;
8/8/2019 Copy of 38 Programsmm
37/49
clrscr();
printf("\nEnter number of parts : ");
scanf("%d" , &n);
printf("\nEnter lower and upper limits :");
scanf("%f %f" , &x[0] , &x[n]);
y[0] = fun(x[0]);
h = (x[n] - x[0])/n ;
printf("\nx y");
printf("\n%8.5f %8.5f" , x[0] ,y[0]);
for(i=1 ; i < n ; i++)
{ x[i] = x[0] + i * h ;
y[i] = fun(x[i]);
printf("\n %8.5f %8.5f " , x[i] , y[i]);
if(i % 2 == 0)
k1 = k1 + 2 * y[i];
else
k2 = k2 + 4 * y[i];
}y[n] = fun(x[n]);
printf("\n %8.5f %8.5f " , x[n] , y[n]);
y[0] = (h / 3.0 ) * (y[0] + y[n] + k1 + k2 );
printf("\nresult =%f \n" , y[0]);
getch();
}
float fun(float x)
{ float g;
g = sin(x) - log(x) + exp(x);
return g;
}
OUTPUT :-Enter number of parts : 6
Enter lower and upper limits :0.2 1.4
x y
0.20000 3.02951
0.40000 2.79753
0.60000 2.89759
0.80000 3.16604
1.00000 3.559751.20000 4.06983
1.40000 4.70418
result = 4.052133program no.31
/*SIMPSION 3/8 RULE */#include
8/8/2019 Copy of 38 Programsmm
38/49
#include
#include
void main()
{ float fun(float);
float h , k1=0.0 , k2=0.0 ;
float x[20] , y[20];
int n , i;
clrscr();
printf("\nEnter number of parts : ");
scanf("%d" , &n);
printf("\nEnter lower and upper limits : ");
scanf("%f %f" , &x[0] , &x[n]);
y[0] = fun(x[0]);
h = (x[n] - x[0])/n ;
printf("\nx y");
printf("\n%8.5f %8.5f" , x[0] ,y[0]);
for(i=1 ; i < n ; i++)
{ x[i] = x[0] + i * h ;y[i] = fun(x[i]);
printf("\n %8.5f %8.5f " , x[i] , y[i]);
if(i % 3 == 0)
k1 = k1 + 2 * y[i];
else
k2 = k2 + 3 * y[i];
}
y[n] = fun(x[n]);
printf("\n %8.5f %8.5f " , x[n] , y[n]);
y[0] = ((3 *h) / 8.0 ) * (y[0] + y[n] + k1 + k2 );
printf("\nresult =%f \n" , y[0]);getch();
}
float fun(float x)
{ float g;
g = sin(x) - log(x) + exp(x);
return g;
}
OUTPUT : -
Enter number of part parts : 6
Enter lower and upper limits : 0.2 1.4
x y
0.20000 3.02951
0.40000 2.79753
0.60000 2.89759
8/8/2019 Copy of 38 Programsmm
39/49
0.80000 3.16604
1.00000 3.55975
1.20000 4.06983
1.40000 4.70418
result = 4.05299
program no.32
/* BOOLS RULE */#include
#include
#include
void main()
{ float fun(float);
float h , k1=0.0 , k2=0.0 , k3=0.0 , k4=0.0;
float x[20] , y[20];
int n , i;
clrscr();printf("\nEnter number of parts");
scanf("%d" , &n);
printf("\nEnter lower and upper limits :");
scanf("%f %f" , &x[0] , &x[n]);
y[0] = fun(x[0]);
h = (x[n] - x[0]) / n;
printf("\nx y");
printf("\n%8.5f %8.5f" , x[0] ,y[0]);
for(i=1 ; i < n ; i++)
{ x[i] = x[0] + i * h ;
y[i] = fun(x[i]);printf("\n %8.5f %8.5f " , x[i] , y[i]);
if(i % 2 == 0)
k1 = k1 + 12 * y[i];
else
k2 = k2 + 32 * y[i];
}
y[n] = fun(x[n]);
printf("\n %8.5f %8.5f " , x[n] , y[n]);
y[0] = ((2 * h)/45) * (7 * y[0] + 7 * y[n] + k1 + k2 +
k3 + k4);
printf("\nresult =%f \n" , y[0]);getch();
}
float fun(float x)
{ float g;
g = log(x);
return g;
8/8/2019 Copy of 38 Programsmm
40/49
}
OUTPUT :-Enter number of parts : 6
Enter lower and upper limits : 4 5.2
x y
4.00000 1.38629
4.20000 1.43508
4.40000 1.48160
4.60000 1.52606
4.80000 1.56862
5.00000 1.60944
5.20000 1.64866
result = 1.814274
program no.33
/* WEEDEL'S RULE */
#include
#include
#include
void main()
{
float fun(float);
float h , k1=0.0 , k2=0.0 , k3=0.0 , k4=0.0;
float x[20] , y[20];
int n , i;
clrscr();printf("\nEnter number of parts : ");
scanf("%d" , &n);
printf("\nEnter lower and upper limits : ");
scanf("%f %f" , &x[0] , &x[n]);
y[0] = fun(x[0]);
h = (x[n] - x[0]) / n;
printf("\nx y");
printf("\n%8.5f %8.5f" , x[0] ,y[0]);
for(i=1 ; i < n ; i++)
{
x[i] = x[0] + i * h ;y[i] = fun(x[i]);
printf("\n %8.5f %8.5f " , x[i] , y[i]);
if(i % 6 == 0)
k1 = k1 + 2 * y[i];
else if(i % 3 == 0)
k1 = k1 + 6 * y[i];
else if(i % 2 == 0)
8/8/2019 Copy of 38 Programsmm
41/49
k1 = k1 + y[i];
else
k4 = k4 + 5 * y[i];
}
y[n]= fun(x[n]);
printf(\nf %8.5f " , x[n] , y[n]);
y[0] = ((3 * h)/10) * (y[0] + y[n] + k1 + k2 + k3 + k4);
printf("\nresult =%f \n" , y[0]);
getch();
}
float fun(float x)
{ float g;
g = sin(x) - log(x) + exp(x);
return g;
}
OUTPUT :-Enter number of parts : 6
Enter lower and upper limits : 0.2 1.4x y
0.20000 3.02951
0.40000 2.79753
0.60000 2.89759
0.80000 3.16604
1.00000 3.55975
1.20000 4.06983
1.40000 4.70418
result = 4.051446
program no.34
/* GAUSS ELIMINATION METHOD */#include
#include
#include
#define n 3
void main()
{
8/8/2019 Copy of 38 Programsmm
42/49
float temp , s , matrix[n][n+1] , x[n];
int i , j , k;
clrscr();
printf("\nEnter the elements of the augment matrix row
wise :\n");
for(i = 0 ; i < n ; i++)
{
for(j=0 ; j
8/8/2019 Copy of 38 Programsmm
43/49
OUTPUT :-
Enter the elements of the augment matrix row wise :
3 1 -1 3
2 -8 1 -5
1 -2 9 8
matrix:-
3.000000 1.000000 -1.000000
3.000000
2.000000 -8.000000 1.000000
-5.000000
1.000000 -2.000000 9.000000
8.000000
Solution is :-
x[1]= 1.0000
x[2]= 1.0000
x[3]= 1.0000
program no 35/* GAUSS JORDAN METHOD */
#include
#include
#include#define n 3
void main()
{
float temp , matrix[n][n+1];
int i , j , k;
clrscr();
printf("\nEnter the elements of the augment matrix row
wise :-\n");
for(i = 0 ; i < n ; i++)
{
for(j=0 ; j
8/8/2019 Copy of 38 Programsmm
44/49
{
temp = matrix[i][j] / matrix[j][j];
for(k = 0 ; k
8/8/2019 Copy of 38 Programsmm
45/49
printf ("\n Enter the number of unknowns=");
scanf ("%d",&n);
for(i=1;i
8/8/2019 Copy of 38 Programsmm
46/49
Enter allowed error, max iteration=0.001 ,4
Iteration x[1]= 0.8500 -1.0275
x[2] = 1.01091 1.0025
x[3] = -0.9998 0.99981
1.0000 - 1.0000 1.0000
x[1]= 1.0000 x[2]=-1.0000 x[3]= 1.0000
Program no.37
/* CURVE FITTING - STRAIGHT LINE */
# include
# include
# include
void main()
{
int i=0,ob;
float
x[10],y[10],xy[10],x2[10],sum1=0,sum2=0,sum3=0,sum4=0;clrscr();
double a,b;
printf("\n Enter the no. of observations :");
scanf(%d,&ob);
printf("\n Enter the values of x :\n");
for (i=0;i
8/8/2019 Copy of 38 Programsmm
47/49
b=(sum2-ob*a)/sum1;
printf("\n\n Equation of the STRAIGHT LINE of the form
y=a+b*x is );
printf("\n\n\t\t\t y=[%f] + [%f]x.a,b);
getch();
}
OUTPUT:Enter the no. of observations : 5
Enter the values of x :
Enter the value of x1 : 1Enter the value of x2 : 2
Enter the value of x3 : 3
Enter the value of x4 : 4
Enter the value of x5 : 5
Enter the values of y :
Enter the value of y1: 14
Enter the value of y2: 27
Enter the value of y3: 40
Enter the value of y4: 55
Enter the value of y5: 68
Equation of the STRAIGHT LINE of the form y=a+b*x is :
y=0 + 13.6 x
Program no.38
/* RUNGA - KUTTA METHOD */
#include
#include
#include
void main()
{
float f(float x , float y);
float x0 = 0.1 , y0 = 1 , xn = 2.1 , h =0.2 , k1 , k2 ,
k3 , k4 ;
int i , n ;
8/8/2019 Copy of 38 Programsmm
48/49
clrscr();
printf("\ndy/dx = (x^3 +y^2)/10 ");
printf("\ngiven y0=1 && x0= 0.1 && h=0.2 (in the range x0
< x < 2.1)\n");
n = (xn - x0) / h;
for(i = 0 ; i
8/8/2019 Copy of 38 Programsmm
49/49
0.500000 y = 1.194833
The solution of differential equation is when x =
0.700000 y = 1.297048
The solution of differential equation is when x =
0.900000 y = 1.436797
The solution of differential equation is when x =
1.100000 y = 1.633150
The solution of differential equation is when x =
1.300000 y = 1.914011
The solution of differential equation is when x =
1.500000 y = 2.322503
The solution of differential equation is when x =
1.700000 y = 2.931453
The solution of differential equation is when x =
1.900000 y = 3.880822
The solution of differential equation is when x =
2.100000 y = 5.495997