Skip to content

Instantly share code, notes, and snippets.

@taiar
Created September 4, 2014 04:21
Show Gist options
  • Save taiar/f4067d80feba403339ca to your computer and use it in GitHub Desktop.
Save taiar/f4067d80feba403339ca to your computer and use it in GitHub Desktop.
Integral with trapezium
#include <stdio.h>
#include <math.h>
double integral(double(*function)(double), double a, double b) {
double start = a;
double adder = 0.0001;
double end = a + adder;
double val = 0;
while(end < b) {
val += (((*function)(end)+(*function)(start))*(end-start))/2;
start = end;
end += adder;
}
return val;
}
double expressao(double x) {
return pow(x, 2)/pow(3, x);
}
int main() {
printf("%lf\n", integral(expressao, 1, 999));
return 0;
}
@Lmanangka
Copy link

ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment