Nhập vào một dãy số kiểm tra có bao nhiêu số nguyên tố

Photo of author

By Skylar

Nhập vào một dãy số kiểm tra có bao nhiêu số nguyên tố

0 bình luận về “Nhập vào một dãy số kiểm tra có bao nhiêu số nguyên tố”

  1. Program BTT;
    Uses crt;
    Var A: array[1..100] of longint;
        n,i,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);
            d:=0;
            For i:=1 to n do
            Begin
                    Write(‘A[‘,i,’] = ‘); Readln(A[i]);
                    If ngto(A[i]) then inc(d);
            End;
            Write(‘Co ‘,d,’ so nguyen to’);
            Readln
    End. 

Viết một bình luận