viết chương trình nhập dữ liệu từ tệp ‘ songuyen.txt’ . tính tổng các số nguyên dương rồi ghi vào tệp ‘ketqua.txt’

viết chương trình nhập dữ liệu từ tệp ‘ songuyen.txt’ . tính tổng các số nguyên dương rồi ghi vào tệp ‘ketqua.txt’

0 bình luận về “viết chương trình nhập dữ liệu từ tệp ‘ songuyen.txt’ . tính tổng các số nguyên dương rồi ghi vào tệp ‘ketqua.txt’”

  1. const fi=’dulieu.txt’;

    fo=’ketqua.txt’;

    var i,t:integer;

    f1,f2:text;

    a:array[1..9]of integer;

    begin assign(f1,fi);

    reset(f1);

    assign(f2,fo);

    rewrite(f2);

    t:=0;

    for i:=1 to 9 do

    begin

    read(f1,a[i]);

    t:=t+a[i];

    end;

    writeln(f2,t);

    close(f1);

    close(f2);

    end.

    học tốt 

    Bình luận
  2. uses crt;
    var  a : array[1..100] of integer;
     n,i,t : integer;
    begin clrscr ;
    assign(input,’songuyen.text’);
    assign(output,’Ketqua.txt’);
    reset(input);            rewrite(output);
    readln(input,n);
    t:=0;
    for i:=1 to n do read(input,a[i]);
    for i:=1 to n do if a[i]>0 then t:=t+a[i];
    writeln(output,t);
    close(input);
    close(output);
    readln
    end.

    Bình luận

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