viết chương trình nhập vào 1 dãy số nguyên có n phần tử, n được nhập từ bàn phím . thông báo ra màn hình -số lớn nhất nhỏ nhất trong dãy số . -có bao nhiêu phần tử chẵn -các phân tử là số nguyên tố

2 câu trả lời

uses crt;
var a:array[1..100]of integer;
n,i,max,min,dem,kt,j:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{------------------------------so-lon-nhat-so-nho-nhat----------------------}
max:=a[1];
min:=a[1];
for i:=1 to n do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('so lon nhat la: ',max);
writeln('so nho nhat la: ',min);
{-----------------------------xuat-so-luong-phan-tu-chan--------------------}
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('so luong phan tu chan trong day la: ',dem);
{-----------------------------xuat-cac-phan-tu-la-so-ngto------------------}
writeln('cac so nguyen to trong day la:');
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to trunc(sqrt(a[i])) do
if a[i] mod j=0 then kt:=1;
if kt=0 then write(a[i]:4);
end;
readln;
end.

program bt;
uses crt;
var A:array[1..1000] of integer;
    i,j,n,max,min,chan:integer;

begin
 clrscr; max:=-10000; min:=10000;
 readln(n);
 for i:=1 to n do
  begin
   read(A[i]);
   if A[i] mod 2=0 then inc(chan);
   if A[i]>max then max:=A[i];
   if A[i]<min then min:=A[i];
  end;
 writeln('So lon nhat: ',max);
 writeln('So nhon nhat: ',min);
 writeln('Co ',chan,' so chan');
 writeln('Cac so nguyen to la: ');
 for i:=1 to n do
  for j:=2 to trunc(sqrt(A[i])) do if A[i] mod j = 0 then break else write(A[i],' ');
 readln;
 readln;
end.

Câu hỏi trong lớp Xem thêm