bài 1:
program tinhtong;
uses crt;
var n,s,i:longint;
begin
clrscr;
repeat
write('nhap so n:');readln(n);
until (n>=10)and(n<100);
s:=0;
for i:=10 to n do
if (i mod 2)=0 then s:=s+i;
write('tong cua cac so co hang don vi chan la:',s);
readln;
end.
bài 2:
program kiem_tra_so_nguyen_to;
uses crt;
var n,j,i:longint;
begin
clrscr;
write('nhap so n:');readln(n);
j:=0;
for i:=1 to n do
if (n mod i)=0 then j:=j+1;
if j=2 then write(n,'la so nguyen to')
else write(n,'khong phai la so nguyen to');
readln;
end.
Cách khác:
Bài 2:
uses crt;
var n,i,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
if n>1 then
begin
kt:=0;
for i:=2 to n-1 do
if n mod i=0 then kt:=1;
if kt=0 then writeln(n,' la so nguyen to')
else writeln(n,' la hop so');
end
else writeln(n,' khong la so nguyen to cung khong la hop so');
readln;
end.