viết chương trình nhập dãy A gồm n nguyên (n <= 100) a) đếm số lượng các số lẻ ở vị trí chẵn b) tính tổng giá trị các số nguyên tố trong dãy

1 câu trả lời

Program BTH;
Uses crt;
var i,tong,dem:longint;a:array[1..100] of longint;
function kiemtra(a:longint):boolean; var j:longint;
begin if a<2 then exit(false) else if a<4 then exit(true);
for j:=2 to trunc(sqrt(a)) do if a mod j=0 then exit(false); exit(true); end;
begin
clrscr;
for i:=1 to 100 do begin write('nhap a[',i,']');read(a[i]);
if (not odd(i))and(odd(a[i])) then inc(dem);
if kiemtra(a[i]) then tong:=tong+a[i] end;
writeln('co ',dem,' so');
writeln('tong la ',tong);
readln;
end.