câu 1:
uses crt;
var p,i:integer;
begin
clrscr;
p:=1;i:=1;while i<=5 do
begin
p:=p*i;i:=i+1;
end;
write(p);
readln;
end.
bai 2:
uses crt;var p,i:integer;begin clrscr; p:=1; i:=0; while i <=10 do begin
i:=i+1; if (i mod 2<>0) then p:=p*i; end; write(p); readln;end. bai 3:
uses crt;var n,i,p:integer;begin clrscr; write('nhap n: '); readln(n); i:=1; p:=1; while i<=n do begin if i mod 2=0 then p:=p*i; i:=i+1; end; write(p); readln;end.
*Cách khác: Dùng for
Câu 1:
uses crt;
var p,i:longint;
begin
p:=1;
for i:=1 to 4 do
p:=p*i;
writeln(p);
readln;
end.
Câu 2:
uses crt;
var i,s:longint;
begin
clrscr;
s:=1;
for i:=1 to 10 do
if i mod 2=1 then s:=s*i;
writeln(s);
readln;
end.
Câu 3:
uses crt;
var n,i,s:longint;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
if i mod 2=0 then s:=s+i;
writeln(s);
readln;
end.