Possible Duplicate:
Merging two modules into one. The first is an equation; the second takes the integral of this equation
#include <stdio.h>
#include <math.h>
double f(double x){
return (x*x);
}
double integrateF(double (function)(double) ){
double area;
double x_width;
int k; // Counter necessary for For-Loop
int n; // # of bars
double min; // Limit min
double max; // Limit max
printf("Please enter the limit minima, 'a'==>\n");
scanf("%lf",&min);
printf("Please enter the limit maxima, 'b'==>\n");
scanf("%lf",&max);
printf("Please enter # of bars needed to span [a,b]==>\n");
scanf("%d",&n);
x_width=(max-min)/n;
for(k=1;k<=n;k++){
area+=function(min+x_width*(k-0.5));
}
area*=x_width;
return area;
}
int main(void){
double resultant;
resultant=integrateF(f);
printf("The value of the integral is: %f \n",resultant);
return 0;
}
Evening all,
My first module consists of the function (x^2). The returned value proceeds onto integrateF(f), which then initializes the second module. This is when things get messy...
What does this line do?
double integrateF(double (function)(double) ){
Important note: My program runs smoothly but I have no idea why because of this line.
Is there any way I can remodel this code to exclude my first module AND this odd line (and whatever needs to go can go as well) so I only have the integration module that nests the (x^2) function.
My main(void) module can stay, of course.