Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
riemann
//g++ 7.4.0 //riemann function //credit for riemann function code goes to John R Hubbard, University of Richmond; other function and test driver codes are created by Rezaul Hoque on July 23,2021; contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <cmath> using namespace std; double riemann(double (*)(double),double, double,int); double sroot(double); double expo(double); double riemann(double (*pf)(double t), double a, double b, int n){ double s=0, h=(b-a)/n, x; int i; for (x=a, i=0;i<n; x+=h, i++) s += (*pf)(x); return s*h; } double sroot(double b){//same as sqrt defined in cmath return(pow(b,0.5)); } double expo(double t){// same as exp defined in cmath return(pow(2.71828,t)); } int main() { cout<<riemann(sroot, 1,4,1000)<<endl; cout<<riemann(cos,0,3.1416/2,1000)<<endl; cout<<riemann(expo, 0,1,1000)<<endl; cout<<riemann(log, 1,2.71828,1000)<<endl; return 0; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
static_cast makes a copy
max subsequence of array
ThreeVariableRegression
Hello world!
HeapSort
Expected types
e-olymp.com---problem1590---Birthday 2
Identifying polimorphic types without using RTTI or type mappings
Why C++ optimizer has problems with these temporary variables
20201123
Please log in to post a comment.