I am trying to write a program to find the integrals of a function, where the computer determines the number of slices that it should use, going through a loop until it finds the change small enought to ignore. I want it to have a tolerance of .01%

Can anyone whip up a bit of code?

This isn't for a class....personal useage. Im just blank on how to start it for the loop.

Edit: This is what I have for code thus far...but I think I don't have it set up right to include the loop that I need. Also, for N, I want to start at 25 and bump it up by 25 through each loop....

double myfunction(double) ;



double integrate(double lower, double upper, int N)
{
	
    double width = (upper - lower) / N ;  
	double sum = 0.0 ;  
	double x ; 
	int i ;  
	for(i = 0 ; i < N ; i++ )
	{
		x = lower + width * (i + 0.5) ;
		
		sum += width * myfunction(x) ;

	}

>Also, for N, I want to start at 25 and bump it up by 25 through each loop...
If I understand correctly.

for (i = 25 ; i < N ; i += 25 )

You are not returning the final result of sum.

how to write the C program of pyramid:
1
2 3
4 5 6

7 8 8 10

Start a new thread for that. Sheesh!

This article has been dead for over six months. Start a new discussion instead.