Viết chương trình Pascal nhập một dãy số có n phần tử với n được nhập từ bàn phím. Thực hiện các công việc sau :
a) Tìm số lớn nhất có trong dãy đó
b) Tìm số nhỏ nhất có trong dãy đó
c) In ra các số chia hết cho 3
d) In ra các số nguyên tố có trong dãy.
còn 1 câu muốn đặt nx ><
program baitap;
uses crt;
var a : array[1..100] of integer;
i ,n ,max,min ,s : integer;
function snt(x : integer) : boolean;
var i,d : integer;
begin d:=0;
for i:=1 to x do if x mod i = 0 then d:=d+1;
if d = 2 then snt:=true else snt:=false;
end;
begin clrscr;
write(‘Nhap so n :’); readln(n);
for i:=1 to n do begin
write(‘Nhap phan tu thu ‘,i,’ la :’);
readln(a[i]); end;
max:=a[1];
for i:=2 to n do if max < a[i] then max:=a[i];
min:=a[1];
for i:=2 to n do if min > a[i] then min:=a[i];
writeln(‘Gia tri lon nhat la :’, max);
Writeln(‘Gia tri nho nhat la:’, min);
writeln(‘Cac phan tu chia het cho 3 la:’);
for i:=1 to n do
If a[i] mod 3 = 0 then write(a[i]:3);
writeln;
writeln(‘Cac so nguyen to co trong day la :’);
for i:=1 to n do if snt(a[i]) = true then write(a[i]:3);
readln;
end.
Program Hotboy;
Uses crt;
Var a:array[1..100] of integer;
Max,min,nt,j:longint;
i,n : byte;
Function snt(m : integer) : boolean;
begin
nt:=0;
For i:=1 to m do
if m mod i = 0 then inc(nt);
if (nt= 2 ) then snt:=true else snt:=false;
end;
Begin
Clrscr;
Write(‘nhap n ‘);
Readln(n);
For i:=1 to n do
Begin
Write(‘A[‘,i,’]’);
Readln(A[i]);
End;
Max:=A[1];
Min:= A[1];
For i:= 2 to n do
If (A[i] > max) then Max:= A[i];
If (A[i] < min ) then Min :=A[i];
Writeln(‘so nho nhat la’,min,’ so lon nhat la’,max);
For i:=1 to n do
If (A[i] mod 3=0) then writeln(‘so chia het cho 3 la’,A[i]:3:2);
For i:=1 to n do
If snt(A[i])= true then write(a[i],’ ‘);
Readln
End.