Please @Danjes, DON'T START A NEW THREAD ON THE SAME TOPIC - it confuses everything.
1 2
|
double x[10], y[10];
double x[n],y[n];
|
Does this not look wrong to you?
Irrespective of the C++ errors here, you do NOT need arrays at all. Please read below.
You have an n-loop enclosing an i-loop on lines 25-34. Both of these close, but you do not need this segment of code at all (except for the
h=(b-a)/n;
line which can be moved to later).
You need an n loop to enclose lines lines 36 to 49. It should start with the interval calculation
h=(b-a)/n;
. That should be followed by re-setting
sum to zero for each value of n.
You are confusing
sum and
sum1. I think they are the same variable.
Instead of using your y-array on line 38 you can evaluate the function here - it is only used once:
sum = sum+4*f( a+i*h );
Something similar can be done on line 42.
There appears to be a minor discrepancy (+0.2 or -0.2) between the function calculated on line 8 and that stated on line 21. Only you know which is correct.
PLEASE USE CONSISTENT AND SENSIBLE INDENTATION. Look at your code in tags above.