1.采用递归的方法,完成的功能是:输入两个数a,b,求出a的阶乘与b的阶乘之和
发布网友
发布时间:2022-05-04 12:04
我来回答
共1个回答
热心网友
时间:2023-10-22 13:53
1.
program ex1;
function f(n:longint):longint;
begin
if n=1 then f:=1 else f:=n*f(n-1);
end;
var a,b:longint;
begin
readln(a,b);
writeln(f(a)+f(b));
end.
2.
program ex2;
function GreatestCommonDivisor(a,b:integer):integer;
var x:integer;
begin
x:=a;
if b<x then x:=b;
while (a mod x<>0)or(b mod x<>0) do x:=x-1;
GreatestCommonDivisor:=x;
end;
function LeastCommonMultiple(a,b:integer):integer;
var x:integer;
begin
x:=a;
if b>x then x:=b;
while (x mod a<>0)or(x mod b<>0) do x:=x+1;
LeastCommonMultiple:=x;
end;
var n,m:integer;
begin
readln(n.m);
writeln('*=',GreatestCommonDivisor(n,m));
writeln('lcm=',LeastCommonMultiple(n,m));
end.
热心网友
时间:2023-10-22 13:53
1.
program ex1;
function f(n:longint):longint;
begin
if n=1 then f:=1 else f:=n*f(n-1);
end;
var a,b:longint;
begin
readln(a,b);
writeln(f(a)+f(b));
end.
2.
program ex2;
function GreatestCommonDivisor(a,b:integer):integer;
var x:integer;
begin
x:=a;
if b<x then x:=b;
while (a mod x<>0)or(b mod x<>0) do x:=x-1;
GreatestCommonDivisor:=x;
end;
function LeastCommonMultiple(a,b:integer):integer;
var x:integer;
begin
x:=a;
if b>x then x:=b;
while (x mod a<>0)or(x mod b<>0) do x:=x+1;
LeastCommonMultiple:=x;
end;
var n,m:integer;
begin
readln(n.m);
writeln('*=',GreatestCommonDivisor(n,m));
writeln('lcm=',LeastCommonMultiple(n,m));
end.
热心网友
时间:2023-10-22 13:53
1.
program ex1;
function f(n:longint):longint;
begin
if n=1 then f:=1 else f:=n*f(n-1);
end;
var a,b:longint;
begin
readln(a,b);
writeln(f(a)+f(b));
end.
2.
program ex2;
function GreatestCommonDivisor(a,b:integer):integer;
var x:integer;
begin
x:=a;
if b<x then x:=b;
while (a mod x<>0)or(b mod x<>0) do x:=x-1;
GreatestCommonDivisor:=x;
end;
function LeastCommonMultiple(a,b:integer):integer;
var x:integer;
begin
x:=a;
if b>x then x:=b;
while (x mod a<>0)or(x mod b<>0) do x:=x+1;
LeastCommonMultiple:=x;
end;
var n,m:integer;
begin
readln(n.m);
writeln('*=',GreatestCommonDivisor(n,m));
writeln('lcm=',LeastCommonMultiple(n,m));
end.