File tree 2 files changed +43
-0
lines changed
Third Year/Fifth Semester/Numerical Method Lab
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < stdio.h>
2
+ #include < conio.h>
3
+ #include < math.h>
4
+ #define f (x ) (x*exp (x))
5
+
6
+ int main(){
7
+ float a,b,h,sum=0 ;
8
+ int i,n;
9
+ printf (" Enter upper limit a and lower limit b: " );
10
+ scanf (" %f %f" , &a, &b);
11
+ printf (" Enter no of intervals: " );
12
+ scanf (" %d" ,&n);
13
+ h=(b-a)/n;
14
+ sum=f (a)+f (b);
15
+ for (i=1 ;i<n;i++){
16
+ a+=h;
17
+ if ((i%2 )!=0 )
18
+ sum+=4 *f (a);
19
+ else
20
+ sum+=2 *f (a);
21
+ }
22
+ printf (" sum=%f" ,sum*h/3 );
23
+ }
Original file line number Diff line number Diff line change
1
+ #include < stdio.h>
2
+ #include < conio.h>
3
+ #include < math.h>
4
+ #define f (x ) (x*exp (x))
5
+
6
+ int main(){
7
+ float a,b,h,sum=0 ;
8
+ int i,n;
9
+ printf (" Enter upper limit a and lower limit b: " );
10
+ scanf (" %f %f" , &a, &b);
11
+ printf (" Enter no of intervals: " );
12
+ scanf (" %d" ,&n);
13
+ h=(b-a)/n;
14
+ sum=f (a)+f (b);
15
+ for (i=1 ;i<n;i++){
16
+ a+=h;
17
+ sum+=2 *f (a);
18
+ }
19
+ printf (" sum=%f" ,sum*h/2 );
20
+ }
You can’t perform that action at this time.
0 commit comments