Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Phạm Thị Kim Liên, THCS Hoàng Động, Thủy Nguyên.

CAUHOI
Câu 2. (3,5 điểm)
Nhập vào một dãy số nguyên n phần tử, n nhập từ bàn phím.
a- In ra màn hình dãy số vừa nhập xếp theo thứ tự tăng dần.
b- In ra màn hình các số nguyên tố trong dãy số vừa nhập và đếm xem đã
nhập vào bao nhiêu số nguyên tố.
Bai2.inp Bai2.out
5 Mang sau khi da sap xep la -6 2 3 5 30
2 3 5 -6 30 Nhung so nguyen to trong mang la 2 3 5
so phan tu la so nguyen to trong mang la:3

DAPAN
Uses crt;
Const finp='Bai2.inp';
fout='Bai2.out';
Type Mat=Array[1..300] of Longint;
var a,b,c,d:mat;
f:text;
i,n:longint;
Procedure Docfile;
Begin
Assign(f,finp);
Reset(f);
Readln(f,n);
For i:=1 to n do
Read(f,a[i]);
Close(f);
End;
Procedure Ghifile;
Begin
Assign(f,fout);
Rewrite(f);
End;
function NT(n:longint):boolean;
var i:longint;
Kt:boolean;
begin
Kt:=true;
for i:=2 to round(sqrt(n)) do
if n mod i=0 then Kt:=false;
NT:=Kt;
end;
Procedure Xuli;
Var j,dem,tg: Integer;
Begin
For i:= 1 to n-1 do
For j:= i to n do
If a[i]>a[j] then
Begin
tg:= a[i];
a[i]:=a[j];
a[j]:= tg;
End;
Ghifile;
Write(f,'Mang sau khi da sap xep la');
For i:= 1 to n do Write(f,a[i]:4);
Writeln(f,'');
dem:=0;
For i:=1 to n do
If (a[i]>=2) and NT(a[i]) then
dem:= dem+1;
if dem=0 then
writeln(f,'Khong co so NT trong mang!')
else
Write(f,'Nhung so nguyen to trong mang la: ');
For i:=1 to n do
If (a[i]>=2) and NT(a[i]) then
Write(f,a[i]:4);
Writeln(f,''); Write(f,'so phan tu la so nguyen to trong mang la: ',dem) ;
End;
Begin
Docfile;
Xuli;
Close(f);
End.

You might also like