making a table showing approximated integral at each row

Hi I have an assignment were I need to find the area under a function x^2 by using middlesums/riemann sum. the output needs to be a table with the number of rows to the left, the number of intervals under the curve in the middle and the approximated area to the right. the number of intervals(n) with regards to rows(N) is n=2^(N-1). How do I make a loop where if fx I want 10 rows I get a table were the 1st row shows the area under the curve with 1 interval then row 2 with 2 intervals then row 3 with 4 etc. So far I have the following, which is a little modification from a previous assignment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  #include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

double f(double x);


int main(){

		double sum,x,dx,a,b;
		int n,N,k;

		cout<<"\n Indtast a";
		cin>>a;

		cout<<"\n Indtast b";
		cin>>b;

		do
				{
					cout<<"\n Indtast N:";
					cin>>N;
					dx=(b-a)/pow(2,(N-1));
					sum=0;
					n=pow(2,(N-1));
					x=a-(dx/2);
					for(k=1; k<=N; k=k+1)
					{
						x=x+dx;
						sum=sum+f(x)*dx;
					}

					
				}
				while(k<N);

				return 0;
}
Topic archived. No new replies allowed.