2 câu trả lời
uses crt;
var n,i:longint;s,s1:string;
{====================congsolon====================}
function add(a,b:string):string;
var i,x,y,du,s:longint;
c:string;
begin
while (length(a)<length(b)) do a:='0'+a;
while (length(a)>length(b)) do b:='0'+b;
du:=0;c:='';
for i:=length(a) downto 1 do
begin x:=ord(a[i])-48;
y:=ord(b[i])-48;
s:=x+y+du;
du:=s div 10;
c:=chr(s mod 10+48)+c;
end;
if (du>0) then c:='1'+c;
add:=c;
end;
{====================nhansolon====================}
function nhan(a,b:string):string;
var n,i,j:longint;s,t:string;
begin
n:=-1;s:='';
for i:=length(a) downto 1 do
begin n:=n+1;t:='';
for j:=1 to ord(a[i])-48 do t:=add(t,b);
for j:=1 to n do t:=t+'0';
s:=add(t,s);
end;
nhan:=s;
end;
{====================chuongtrinh====================}
begin
readln(f,n);
s1:='1';
for i:=1 to n do
begin
str(i,s);
s1:=nhan(s1,i);
end;
write(s1);
readln
end.
* Pascal:
uses crt;
var n:longint;
{---Ham-giai-thua---}
function gt(n:longint):longint;
var i:longint;
begin
gt:=1;
for i:=1 to n do gt:=gt*i;
writeln(n,'!=',gt);
end;
{---Chuong-trinh-chinh---}
begin
clrscr;
repeat
write('Nhap n (n<=100): '); readln(n);
until n<=100;
gt(n);
readln
end.
* C++:
#include<bits/stdc++.h>
using namespace std;
//Ham giai thua
void giaithua(int n){
int gt=1;
for (int i=1;i<=n;i++)
gt=gt*i;
cout<<n<<"!="<<gt;
}
//Chuong trinh chinh
int main(){
int n;
cout<<"Nhap n (n<=100): "; cin>>n;
giaithua(n);
}
* Python:
def gt(n):
gt = 1
for i in range(1,n+1):
gt = gt * i
return gt
n = int(input("Nhap n (n<=100): "))
print(n,"!=",gt(n))