uses crt; var n,i,d:longint; begin clrscr; write(‘n=’);readln(n); for i:=1 to n do if i mod 2=0 then inc(d); writeln(‘Co ‘,d,’ so chan <=n’); readln; end.
C2.
uses crt; var n:longint; begin clrscr; write(‘n=’);readln(n); if n mod 2=1 then dec(n); writeln(‘Co ‘,n div 2,’ so chan <= n’); readln; end.
uses crt;
var n,i,d: integer;
begin
clrscr;
write (‘nhap n: ‘): readln (n);
for i:=1 to n do
if i mod 2=0 then d:=d+1;
writeln (‘cac so chan nho hon hoac bang n la: ‘,d);
readln;
end.
Bài này có 2 cách làm:
C1.
uses crt;
var n,i,d:longint;
begin
clrscr;
write(‘n=’);readln(n);
for i:=1 to n do if i mod 2=0 then inc(d);
writeln(‘Co ‘,d,’ so chan <=n’);
readln;
end.
C2.
uses crt;
var n:longint;
begin
clrscr;
write(‘n=’);readln(n);
if n mod 2=1 then dec(n);
writeln(‘Co ‘,n div 2,’ so chan <= n’);
readln;
end.