Created
September 4, 2014 04:21
-
-
Save taiar/f4067d80feba403339ca to your computer and use it in GitHub Desktop.
Integral with trapezium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ty