codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
/* Simpsons 1/3 rule */ #include<math.h> #include<stdio.h> #include<conio.h> float f(float x) { float f; f=sin(x); return(f); } // #define f(x) (1/(1+x*x)) main() { float a,b,h,simp; int n,k; printf("Value of a,b,n "); scanf("%f%f%d",&a,&b,&n); h=(b-a)/n; simp=f(a)+f(b); for(k=1;k<n;k=k+2) { simp=simp+4*f(a+h*k); } for(k=2;k<n;k=k+2) { simp=simp+2*f(a+h*k); } simp=simp*h/3; printf("\n simp=%f",simp); getch(); }
Private
[
?
]
Run code
Submit