Viết chương trình đọc dữ liệu từ tệp MANG.INP có cấu trúc như sau: - Dòng 1: Số nguyên dương N là số lượng phần tử trong mảng 1 chiều - Dòng 2: Giá trị của N phần tử a1, a2,..., aN Tính tổng các phần tử chẵn trong mảng và đưa kết quả ra màn hình

2 câu trả lời

uses crt;
var f:text;
    n,i,res:longint;
    a:array[1..100]of longint;
begin
clrscr;
    assign(f,'MANG.INP');reset(f);
        readln(f,n);
        for i:=1 to n do read(f,a[i]);
    close(f);
    assign(f,'MANG.OUT');rewrite(f);
        for i:=1 to n do
            if a[i] mod 2=0 then inc(res,a[i]);
        write(f,res);
    close(f);
end.

uses crt;
var i,n,s:integer;
    a:array[1..1000] of integer;
const Fi='MANG.INP';
      Fo='MANG.OUT';

begin
 assign(input,Fi); reset(input);
 assign(output,Fo); rewrite(output);
 readln(n);
 s:=0;
 For i:=1 to n do
  begin
   read(a[i]);
   if a[i] mod 2=0 then s:=s+a[i];
  end;
 writeln(s);
 readln;
end.

Vote cho mik hay nhất nha :3