/*PROGRAM FOR TRAPEZOIDAL RULE OF NUMERICAL INTEGRATION*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(X) (4*X-(3*(X*X)))
void main() {
int i,n;
float a,b,h,x[20],y[20],j;
clrscr();
printf("Enter upper limit,lower limit & sub interval:");
scanf("%f %f %d",&a,&b,&n);
x[0]=b;
h=(a-b)/n;
for(i=0;i<=n;i++) {
y[i]=f(x[i]);
x[i+1]=x[i] + h;
}
j=y[0];
for(i=0;i<=n-1;i++)
j=j + ((h/2) * (y[i]+y[i+1]));
printf("The required value is=%f ", j);
getch();
}
/*OUTPUT:-
Enter upper limit,lower limit & sub interval:1
0
10
The required value is=0.995000 */
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(X) (4*X-(3*(X*X)))
void main() {
int i,n;
float a,b,h,x[20],y[20],j;
clrscr();
printf("Enter upper limit,lower limit & sub interval:");
scanf("%f %f %d",&a,&b,&n);
x[0]=b;
h=(a-b)/n;
for(i=0;i<=n;i++) {
y[i]=f(x[i]);
x[i+1]=x[i] + h;
}
j=y[0];
for(i=0;i<=n-1;i++)
j=j + ((h/2) * (y[i]+y[i+1]));
printf("The required value is=%f ", j);
getch();
}
/*OUTPUT:-
Enter upper limit,lower limit & sub interval:1
0
10
The required value is=0.995000 */
No comments:
Post a Comment