Wednesday, February 4, 2009

Factorial

we often finish the factorial case with formula like this:


general formula =
n!=n*(n-1)*((n-1)-1).....*1

for the example:

5! =5*4*3*2*1

3! =3*2*1

We can finish the factorial case with statement like this :

program faktorial;
uses crt;
var I,N,fak: integer ;
begin
resdln(N) ;
fak:=1
for I:=1 to N do
fak:=fak*I;
writeln(fak);
readln;
end.

if we run the statement,we are get output like this :

fak

2 comments:

gredinov said...

kenapa ketika faktorial lebih besar dari 8, hasilnya kacau?

Ricky said...

lha kan fak nya saya buat integer,coba deh anda buat longint aja supaya lebih muat banyak angkanya