nhập vào n số nguyên n (0<=n<=30) . tính n ! cần gấp mn

1 câu trả lời

uses crt;
type BIGNUMBA = AnsiString;
var ans: BIGNUMBA;
    n, i: longint;

function mul(a:BIGNUMBA; b:longint): BIGNUMBA;
var i, carry, sum:longint;
    ans, tmp: BIGNUMBA;
begin
    ans:=''; carry:=0;

    for i:=length(a) downto 1 do
        begin
            sum:=(ord(a[i]) - 48) * b + carry;
            carry:=sum div 10;
            ans:=chr(sum mod 10 + 48) + ans;
        end;

    if(carry > 0) then str(carry,tmp) else tmp:='';
    exit(tmp + ans);
end;

begin
clrscr;
    readln(n);
    
    if n = 0 then
        writeln(1)
    else
        ans:='1';
        for i:=1 to n do
            ans:=mul(ans, i);

        writeln(ans);
readln;
end.