Integrals

f is a function, defined over [0, 1].

h=0.02; (* step length *)
n=1/h; (* how many steps *)
f[x_]:=x;
(*1, x, x^2,  Sin[3x], Sin[6x], Sin[12x], Sin[12x]-x *)

box[x_,h_]:=Line[{{x,0},{x+h,0},{x+h,f[x]},{x,f[x]},{x,0}}];
boxes[h_]:=Table[box[x,h],{x,0,1-h,h}];
boxplot=Graphics[boxes[h]];
fplot=Plot[{Red,f[x]},{x,0,1},PlotStyle->Thick,Filling->Axis,PlotRange->All,AxesOrigin->{0,0}];
Show[fplot,boxplot]

ff[i] keeps track of how many box areas have been used for area[f], i.e., ff[i]=area of f over [0,i/n].

ff[i_]:=If[i==0,0,ff[(i-1)]+h*f[i*h]];

areaplot[n_]:=ListLinePlot[Table[ff[i],{i,0,n}],PlotStyle->Thick,DataRange->{0,1},PlotRange->All,AxesOrigin->{0,0}];

Show[{areaplot[n],boxplot,fplot}]

Print["area over [0,1]: ",Integrate[f[x],{x,0,1}]//N];