program giai_thua; uses Crt; var n:Integer; function giaithua(n:Integer):LongInt; begin if n=0 then giaithua:=1 else giaithua:=n*giaithua(n-1); end; begin clrscr; Write(‘Ban muon tinh giai thua cua bao nhieu: ‘); ReadLn(n); WriteLn(n,’!= ‘,giaithua(n)); ReadLn; end.
#include <iostream> using namespace std; int main() { int n; lòng giaiThua = 1; cout << “Nhập số n: “; cin >> n; for(int i = 1; i <= n; i++) { giaiThua = giaiThua * i; } cout << “Giai thừa của ” << n << ” là ” << giaiThua << endl; return 0; }
program giai_thua;
uses Crt;
var n:Integer;
function giaithua(n:Integer):LongInt;
begin
if n=0 then
giaithua:=1
else
giaithua:=n*giaithua(n-1);
end;
begin
clrscr;
Write(‘Ban muon tinh giai thua cua bao nhieu: ‘);
ReadLn(n);
WriteLn(n,’!= ‘,giaithua(n));
ReadLn;
end.