The document contains programs written in C programming language to solve problems using numerical methods like Bisection method, False position method, Trapezoidal rule, Simpson's rule, Runge-Kutta method, Euler's method, and Lagrange interpolation. The programs take user input, perform the respective calculations, and output the results. They provide examples of implementing numerical techniques to find roots of equations, compute integrals, and solve differential equations.
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
Bubble Sort,Insertion Sort, Structures,Students Mark statement ,Pointers, Arithmetic operations on pointers, Files,Creating file, Reading file,Writing a text file,binary file,lab programs,c programs,example programs,c program,Bubble Sort in c,Insertion Sort in c, Structures in c,Students Mark statement in c ,Pointers in c, Arithmetic operations on pointers in c, Files in c,Creating file in c, Reading file in c,Writing a text file in c,binary file in c,lab program in c,c program,example program,c program,thiruvalluvar university,lab manual,c lab manual
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
Bubble Sort,Insertion Sort, Structures,Students Mark statement ,Pointers, Arithmetic operations on pointers, Files,Creating file, Reading file,Writing a text file,binary file,lab programs,c programs,example programs,c program,Bubble Sort in c,Insertion Sort in c, Structures in c,Students Mark statement in c ,Pointers in c, Arithmetic operations on pointers in c, Files in c,Creating file in c, Reading file in c,Writing a text file in c,binary file in c,lab program in c,c program,example program,c program,thiruvalluvar university,lab manual,c lab manual
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
1. PROGRAM
/*program for legranges interpolation method*/
#include<stdio.h>
#include<conio.h>
void main()
{
float x[20],y[20],unknown,temp,result=0,n,i,j;
clrscr();
printf("nntLEGRANGES INTERPOLATION -FIRST ORDERn");
printf("nt---------------------------------------n");
printf("nEnter the limitn");
scanf("%f",&n);
printf("Enter the values for xn");
for(i=0;i<n;i++)
{
scanf("%f",&x[i]);
}
printf("Enter the values of yn");
for(i=0;i<n;i++)
{
scanf("%f",&y[i]);
}
printf("Enter the value whose f(x) to be foundn");
scanf("%f",&unknown);
for(i=0;i<n;i++)
{
temp=1;
for(j=0;j<n;j++)
{
if(i!=j)
{
temp*=((unknown-x[j])/(x[i]-x[j]));
}
}
result+=temp*y[i];
}
printf("f( %f )= ",unknown);
printf("%f",result);
getch();
}
St.Mary’scollege,Thrissur
2. OUTPUT
LEGRANGES INTERPOLATION -FIRST ORDER
------------------------------------------------------------
Enter the limit
4
Enter the values for x
300
304
305
307
Enter the values of y
2.4771
2.4829
2.4843
2.4871
Enter the value whose f(x) to be found
301
F(301.000000) = 2.478597
St.Mary’scollege,Thrissur
3. PROGRAM
/* program to claculate the integral using trezoidal rule*/
#define f(x) (1/(x+1))
#include<stdio.h>
#include<conio.h>
void main()
{
float h,a,b,result=0,temp=0;
int i,j,n;
float x[50],y[50];
clrscr();
printf("Enter the Lower & Upper limit a&bn");
scanf("%f %f",&a,&b);
printf("nEnter the number of intervalsn");
scanf("%d", &n);
h=(b-a)/n;
printf("nCOMPUTING INTEGRAL USING-TRAPEZOIDAL RULE n");
for(i=0;i<=n;i++)
{
x[i]=a+(i*h);
}
for(i=0;i<=n;i++)
{
y[i]=f(x[i]);
}
printf("xttty");
for(i=0;i<=n;i++)
{
printf("n%ftt%f",x[i],y[i]);
}
result=y[0]+y[n];
for(i=1;i<n;i++)
{
temp+=y[i];
}
result+=(temp*2);
result*=(h/2);
printf("nn%f",result);
getch();
}
St.Mary’scollege,Thrissur
4. OUTPUT
Enter the Lower & Upper limit a&b
0
1
Enter the number of intervals
2
COMPUTING INTEGRAL USING-TRAPEZOIDAL RULE
x y
0.000000 1.000000
0.500000 0.666667
1.000000 0.500000
0.708333
St.Mary’scollege,Thrissur
5. PROGRAM
/*program to solve differential equation using Eulers method*/
#include<stdio.h>
#include<conio.h>
#define f(x,y) ((y-x)/(y+x))
void main()
{
float x0,y0,h,unknown,result=0,temp=0;
printf("nntEULERS METHODn");
printf("nEnter the value for x0n");
scanf("%f",&x0);
printf("Enter the value for y0n");
scanf("%f",&y0);
printf("Enter the steplengthn");
scanf("%f",&h);
printf("Enter the value for unknownn");
scanf("%f",&unknown);
while(x0<=unknown)
{
temp=y0+h*f(x0,y0);
x0+=h;
result=y0;
y0=temp;
}
printf("Result= %f",result);
getch();
}
OUTPUT
EULERS METHOD
--------------
Enter the value for x0
1
Enter the value for y0
2
Enter the steplength
.5
Enter the value for unknown
St.Mary’scollege,Thrissur
6. 2
Result= 2.257576
PROGRAM
/* program to compute integral using legranges interpolation 2nd order*/
#include<stdio.h>
#include<conio.h>
#define f(x) 1/(1+(x*x))
void main()
{
float u,l,b,a,h,result=0;
clrscr();
printf("ntLEGRANGES INTERPOLATION - 2nd ORDERn");
printf("nt-----------------------------------n");
printf("nEnter the upper limit:nt");
scanf("%f",&a);
printf("Enter the lower limit:nt");
scanf("%f",&b);
h=(a-b)/2;
result=f(-0.57735)+f(0.57735);
result*=h;
printf("nnRESULT = %f",result);
getch();
}
LEGRANGES INTERPOLATION - 2nd ORDER
-----------------------------------------------------------
Enter the upper limit:
1
Enter the lower limit:
-1
RESULT = 1.583338
St.Mary’scollege,Thrissur
7. PROGRAM
/* program to solve the 3rd order differential equation using Runge Kutta 2nd order*/
#define f(x,y) x+y
#include<stdio.h>
#include<conio.h>
void main()
{
float x0,y0,y1,k1,k2,h,unknown;
clrscr();
printf("ntRUNGE KUTTA METHOD - 2nd ORDERn");
printf("nt------------------------------n");
printf("nEnter the values for the following:n");
printf("ntx0: ") ;
scanf("%f",&x0);
printf("nty0: ");
scanf("%f",&y0);
printf("nth: ");
scanf("%f",&h);
printf("ntUnknown: ");
scanf("%f",&unknown);
while(unknown!=x0)
{
k1=h*(f(x0,y0));
k2=h*(f(x0+h,y0+k1));
y1=y0+((k1+k2)/2);
x0+=h;
y0=y1;
}
printf("nUNKNOWN = %fnRESULT = %f",unknown,y1);
getch();
}
St.Mary’scollege,Thrissur
8. OUTPUT
RUNGE KUTTA METHOD - 2nd ORDER
-----------------------------------------------------
Enter the values for the following:
x0: 0
y0: 1
h: .1
Unknown: .2
UNKNOWN = 0.200000
RESULT = 1.242050
St.Mary’scollege,Thrissur
9. PROGRAM
/* program using Runge kutta 3rd order method*/
#define f(x,y) x+y
#include<stdio.h>
#include<conio.h>
void main()
{
float y1,x0,y0,k1,k2,k3,h,unknown;
clrscr();
printf("nntRUNGE KUTTA - 3rd ORDERn");
printf("nt-----------------------n");
printf("Enter the values for the folowingn");
printf("ntx0: ");
scanf("%f",&x0);
printf("nty0: ");
scanf("%f",&y0);
printf("nth: ");
scanf("%f",&h);
printf("ntUnknown: ");
scanf("%f",&unknown);
while(unknown!=x0)
{
k1=h*(f(x0,y0));
k2=h*(f(x0+h/2,y0+k1/2));
k3=h*(f(x0+h,y0+2*k2-k1));
y1=y0+(k1+4*k2+k3)/6;
x0+=h;
y0=y1;
}
printf("nn Result of %f = %f",unknown,y1);
getch();
}
St.Mary’scollege,Thrissur
10. OUTPUT
RUNGE KUTTA METHOD - 3rd ORDER
--------------------------------------------------
Enter the values for the folowing
x0: 0
y0: 1
h: .1
Unknown: .2
Result of 0.200000 = 1.242787
St.Mary’scollege,Thrissur
11. PROGRAM
/* program to compute integral using Simpsons rule*/
#define f(x) 1/(1+x)
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,h,result,temp1=0,temp2=0;
float x[20],y[20];
int i,j,n;
clrscr();
printf("nntSIMPSONS 1/3rd RULEn");
printf("nt---------------------n");
printf("Enter the Lower and Upper limitsn");
scanf("%f %f",&a,&b);
printf("nEnter the number of intervalsn");
scanf("%d",&n);
h=(b-a)/n;
for(i=0;i<=n;++i)
{
x[i]=a+(i*h);
}
for(i=0;i<=n;++i)
{
y[i]=f(x[i]);
}
printf("nnxttyn");
printf("n-------n");
for(i=0;i<=n;++i)
{
printf("n%ft%f",x[i],y[i]);
}
h=(b-a)/(2*n);
result=y[0]+y[n];
for(i=1;i<=n-1;i+=2)
{
temp1=temp1+y[i];
St.Mary’scollege,Thrissur
13. PROGRAM
/*program to find the integral at a point using modified Eulers method*/
#include<stdio.h>
#include<conio.h>
#define f(x,y) (y-(x*x))
void main()
{
float x0,x1,y1,y0,y2,y3,h,unknown,result;
clrscr();
printf("nntMODIFIED EULERS METHODn");
printf("nt----------------------n");
printf("nEnter the values for the following:n");
printf("ntx0: ");
scanf("%f",&x0);
printf("nty0: ");
scanf("%f",&y0);
printf("ntSteplength: ");
scanf("%f",&h);
printf("ntThe value whose f(x) to be found: ");
scanf("%f",&unknown);
while(x0<=unknown)
{
y1=y0+(h*f(x0,y0));
x1=x0+h;
while(1)
{
y2=y0+(h/2)*(f(x0,y0)+f(x1,y1));
y3=y0+(h/2)*(f(x0,y0)+f(x1,y2));
if(y2==y3)
{
break;
}
y1=y2;
}
x0+=h;
St.Mary’scollege,Thrissur
18. PROGRAM
/*Program for find the root of the equation(x*x*x-x-1) by False position method*/
#define f(x) (x*x*x-x-1)
#include<stdio.h>
#include<conio.h>
void main()
{
float i=0,j=1,f1,f2,x0,fp,fq,x1,x2=0,prev;
clrscr();
while(1)
{
f1=f(i);
f2=f(j);
if((f1<0&&f2>0)||(f1>0&&f2<0)) /* Finding the intervals*/
break;
else
{
i++;
j=i+1;
}
printf("n The Intervals are:t%f,t%fn",i,j);
x0=i;
x1=j;
do
{
prev=x2;
fp=f(x0);
St.Mary’scollege,Thrissur
19. fq=f(x1);
x2=x0-(fp*(x1-x0)/(fq-fp));
printf("Value of x0=%ftValue of x1=%ftValue of x2=%ftValue of
F(x2)=%fn",x0,x1,x2,f(x2));
if(f(x2)<0)
x0=x2;
else
x1=x2;
}while((x2-prev)>.001);
}
printf("nRoot of the equation=%f",x2);
getch();
}
OUTPUT
The Intervals are: 1.000000, 2.000000
Value of x0=1.000000
Value of x1=2.000000
Value of x2=1.166667
Value of F(x2)=-0.578704
Value of x0=1.166667
Value of x1=2.000000
Value of x2=1.253112
Value of F(x2)=-0.285363
Value of x0=1.253112
Value of x1=2.000000
Value of x2=1.293437
Value of F(x2)=-0.129542
Value of x0=1.293437
Value of x1=2.000000
Value of x2=1.311281
Value of F(x2)=-0.056589
St.Mary’scollege,Thrissur
20. Value of x0=1.311281
Value of x1=2.000000
Value of x2=1.318988
Value of F(x2)=-0.024304
Value of x0=1.318988
Value of x1=2.000000
Value of x2=1.322283
Value of F(x2)=-0.010362
Value of x0=1.322283
Value of x1=2.000000
Value of x2=1.323684
Value of F(x2)=-0.004404
Value of x0=1.323684
Value of x1=2.000000
Value of x2=1.324279
Value of F(x2)=-0.001869
Root of the equation=1.324279
St.Mary’scollege,Thrissur
21. PROGRAM
/*Program for find the root of the eqn(x*x*x-2x-5) by Newton Raffson Method
method*/
#define f(x) (x*x*x-2x-5)
#define q(x) (3*x*x-2)
#include<stdio.h>
#include<conio.h>
void main()
{
float i=0,j=1,f1,f2,fp,fq,x1,x2,prev,x0;
clrscr();
printf("nntNEWTON RAFFSON METHODn");
printf("nt---------------------n");
while(1)
{
f1=f(i);
f2=f(j);
if((f1<0&&f2>0)||(f1>0&&f2<0)) /* Finding the intervals*/
break;
else
{
i++;
j=i+1;
}
printf("n The Intervals are:t%f,t%fnn",i,j);
x0=i;
St.Mary’scollege,Thrissur
22. x1=j;
}
x2=(x0+x1)/2;
printf("x2ttf(x2)ttf'(x2)nnn");
while(1)
{
prev=x2; /*Assigning the current value to the previous value*/
x2=prev-(f(prev)/q(prev));
if(x2==prev)
break;
else
printf("%ft%ft%fn",x2,f(x2),q(x2));
}
printf("nn THE ROOT IS =%f",x2);
getch();
}
OUTPUT
NEWTON RAFFSON METHOD
-------------------------------------------
The Intervals are: 1.000000, 2.000000
The Intervals are: 2.000000, 3.000000
x2 f(x2) f'(x2)
2.164179 0.807945 12.051013
2.097135 0.028881 11.193929
2.094555 0.000041 11.161484
2.094552 0.000001 11.161439
THE ROOT IS =2.094552
St.Mary’scollege,Thrissur
23. PROGRAM:
/*program for gauss elimination method…*/
#include<conio.h>
#include<stdio.h>
void main()
{
int m,n,p,q,i,j;
float a[10][10],b[10][10],x,y,z,t; /*…Declaration…*/
clrscr();
printf("nGAUSS ELIMINATION METHODn");
printf("********************************n");
printf("nInput the raw size of first matrix:");
scanf("%d",&m);
printf("Input the column size of first matrix:");
scanf("%d",&n);
printf("nInput the %d elements to %d*%d matrix:nn",m*n,m,n);
for(i=0;i<m;i++) /*…For loop…*/
{
for(j=0;j<n;j++)
{
scanf("%f",&a[i][j]);
}
}
printf("nnInput the raw size of second matrix:");
St.Mary’scollege,Thrissur
26. Matrix A:
4.000000 1.000000 1.000000
3.000000 4.000000 2.000000
2.000000 3.000000 1.000000
Matrix B:
11.000000
11.000000
7.000000
The result is:
x=2.333333
y=0.333333
z=1.333333
PROGRAM
/* program using Newtons divided difference formula*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float d[100][100],result,temp,unknown;
int m,n,i,j,k;
clrscr();
printf("Enter the limitn");
scanf("%d %d",&m,&n);
printf("Enter the values of xn");
for(i=0;i<m;i++)
{
scanf("%f",&d[i][0]);
}
printf("Enter the values of yn");
for(i=0;i<n;i++)
{
St.Mary’scollege,Thrissur
27. scanf("%f",&d[i][1]);
}
printf("Enter the value where f(x) to be foundn");
scanf("%f",&unknown);
printf(" x t y");
for(i=0;i<=(n-2);i++)
{
printf(" ty%d",i);
printf(“---------------------------------------------------------------------“);
}
printf("n");
for(j=2;j<(n+1);j++)
{
k=j-1;
for(i=0;i<(n+1)-j;i++)
{
d[i][j]=(d[i+1][j-1]-d[i][j-1])/(d[k][0]-d[k-(j-1)][0]);
k++;
}
}
k=0;
for(i=0;i<n;i++)
{
printf("nn");
for(j=0;j<=n-k;j++)
{
printf(" %f ",d[i][j]);
}
k++;
}
result=d[0][1];
for(j=2;j<n+1;j++)
{
temp=1;
for(i=0;i<=j-2;i++)
{
temp=temp*(unknown-d[i][0]);
}
result+=temp*d[0][j];
}
printf("nnf(%f) = %f",unknown,result);
getch();
}
St.Mary’scollege,Thrissur
28. OUTPUT
Enter the limit
6
6
Enter the values of x
4
5
7
10
11
13
Enter the values of y
48
100
294
900
1210
2028
Enter the value where f(x) to be found
8
x y y0 y1 y2 y3 y4
--------------------------------------------------------------------------------------
4.000 48.000 52.000 15.000 1.000 0.000 0.000
5.000 100.000 97.000 21.000 1.000 0.000
7.000 294.000 202.000 27.000 1.000
10.000 900.000 310.000 33.000
11.000 1210.000 409.000
13.000 2028.000
f(8.000000) = 448.000000
St.Mary’scollege,Thrissur
29. PROGRAM
/*find the integral using taylor series*/
#include<stdio.h>
#include<conio.h>
#define f1(x,y) (x+(y*y))
#define f2(y,y1) (1+(2*y*y1))
#define f3(y,y1,y2) (2*(y*y2+y1*y1))
#define f4(y,y1,y2,y3) (2*((y*y3+y2*y1)+(2*y1*y2)))
void main()
{
float x0,y0,y1,y2,y3,y4,unknown,h,result=0;
clrscr();
printf("ntTAYLOR SERIESn");
printf("nEnter the initial valuesn");
scanf("%f %f",&x0,&y0);
printf("Enter the unknown value, whose integral to be foundnn");
scanf("%f",&unknown);
St.Mary’scollege,Thrissur