Tin học viết chương trình nhập vào từ bàn phím mảng A gồm n phần tử n<=100 mà phần tử không quá 300. a/tính tổng các phần tử âm b/ đếm trong mảng A có ba 27/07/2021 By Aubrey viết chương trình nhập vào từ bàn phím mảng A gồm n phần tử n<=100 mà phần tử không quá 300. a/tính tổng các phần tử âm b/ đếm trong mảng A có bao nhiêu phần tử dương c/ tính tổng các phần tử chẵn trong dãy d/ tính tổng các số nguyên tố trong dãy
uses crt;var n,i,res,result,sum,count:longint; a:array[1..300]of longint;function isPrimeNumber(n:longint):boolean;var i:longint;begin if n<2 then exit(false); for i:=2 to trunc(sqrt(n)) do if n mod i=0 then exit(false); exit(true);end;beginclrscr; readln(n); for i:=1 to n do begin readln(a[i]); if a[i]<0 then inc(res,a[i]); if a[i]>0 then inc(count); if a[i] mod 2=0 then inc(result,a[i]); if isPrimeNumber(a[i]) then inc(sum,a[i]); end; writeln(‘Tong am: ‘,res); writeln(‘Co ‘,count,’ so duong’); writeln(‘Tong chan: ‘,result); writeln(‘Tong nguyen to: ‘,sum);readln;end. Trả lời
var A: array[1..100] of integer; n, index: byte; tmp: integer; countD: byte; function isPrime(number: integer): boolean; var index: integer; begin if number < 2 then isPrime := false else if number = 2 then isPrime := true else if number mod 2 = 0 then isPrime := false else begin isPrime := true; for index := 3 to int(sqrt(number)) do if number mod index = 0 then begin isPrime := false; break; end; end; end; begin writeln('Nhap so n'); readln(n); index := 1; while index Trả lời