Hey guys I'm trying to figure out how to do factorials in a program. Here is what I have so far: program fact; var n0,n:word; t,an,sum:real; begin write('number of terms n0 equals????'); readln(n0); sum:=0.0; t:=n0; for n:=n0 downto 1 do begin t:=t-1; an:=n0*t; sum:=sum+an; end; writeln('s+sum of 1/n^3 terms from n = 1 to n = ',n0); writeln('s=....',sum); write('press enter...');readln; end. I'm trying to see where I'm going wrong. Any help would be much appreciated.

Is it executing properly? Or coming up with the wrong number? I don't know pascal, but it looks to me like your algorithm is off: Looks like you're adding up a sum of products, right? Well if that's the case, you're figuring your factorials wrong. It's not a sum - t! is the product t * t-1 * t-2 .... * 3 * 2. You're using more variables than you need.

If you can have functions, I would imagine you can use recursion. I know nothing about Pascal though.