Viết chương trình nhập mảng A gồm n phần tử. a, tính tổng các phần tử chia hết cho 2 và 6 b, đếm các phần tử là số nguyên tố

1 câu trả lời

Program FNG;
Uses crt;
Var A: array[1..10000] of longint;
    n,i,s,d: longint;

Function ngto(a: longint): boolean;
Var i: longint;
Begin
        If a<2 then exit(false);
        For i:=2 to a div 2 do
                If a mod i = 0 then exit(false);
        exit(true);
End;

Begin
        Clrscr;
        Write('Nhap n: '); Readln(n);
        s:=0; d:=0;
        For i:=1 to n do
        Begin
                Write('A[',i,'] = ');
                Readln(A[i]);
                If A[i] mod 6 = 0 then s:=s+A[i];
                If ngto(A[i]) then inc(d);
        End;

        Writeln('Tong: ',s);
        Write('Co ',d,' so nguyen to');
        Readln
End.