Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f9a516

Browse files
authored
Merge pull requestTheAlgorithms#146 from JRaiden16/patch-2
Update Simpson's_1-3rd_rule.c
2 parents28e13c6 +811c4db commit1f9a516

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
#include<conio.h>
21
#include<stdio.h>
32
#include<math.h>
4-
floatf(floatx)
3+
4+
floatf(floatx)
55
{
6-
return1.0+x*x*x;
6+
return1.0+x*x*x;//This is the expresion of the function to integrate?
77
}
8+
89
voidmain()
910
{
1011
inti,n;
1112
floata,b,h,x,s2,s3,sum,integral;
12-
printf("enter the lower limit of the integration");
13-
sacnf("%f",&a);
14-
printf("enter the upper limit of the integration");
15-
sacnf("%f",&b);
16-
printf("enter the number of intervals");
17-
sacnf("%d",&n);
13+
14+
printf("enter the lower limit of the integration:");
15+
scanf("%f",&a);
16+
printf("enter the upper limit of the integration:");
17+
scanf("%f",&b);
18+
printf("enter the number of intervals:");
19+
scanf("%d",&n);
20+
1821
h=(b-a)/n;
1922
sum=f(a)+f(b);
2023
s2=s3=0.0;
21-
for(i=1;i<n;i+=3)
24+
25+
for(i=1;i<n;i+=3)
2226
{
2327
x=a+i*h;
2428
s3=s3+f(x)+f(x+h);
2529
}
26-
for(i=3;i<n;i+=3)
30+
31+
for(i=3;i<n;i+=3)
2732
{
2833
x=a+i*h;
2934
s2=s2+f(x);
3035
}
31-
intgral=(h/3.0)*(sum+2*s2+4*s3);
32-
printf("\nvalue of the integral =%9.4f\n",integral);
33-
getch();
36+
37+
integral=(h/3.0)*(sum+2*s2+4*s3);
38+
printf("\nValue of the integral = %9.4f\n",integral);
39+
40+
return0;
3441
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp