Chuyển đến nội dung chính

Bài đăng

Đang hiển thị bài đăng từ Tháng 9, 2016

ví dụ về đọc, ghi dữ liệu vào tệp

uses crt; var N,i:integer;     f,g:Text; function snt( a:integer):boolean; var j:integer; uoc:integer; begin uoc:=0; for j:= 1 to a do if a mod j =0 then uoc:=uoc+1; if uoc=2 then snt:=true else snt:=false; end; begin  assign(f,'bai1.txt') ; {khoi tao}  reset(f);              {doc du lieu}  read(f,n);             {doc du lieu vao bien N}  close(f) ;                   {dong tep}  assign(g,'kqbai1.txt') ; {khoi tao}  rewrite(g);              {tao tep tin moi}  for i:=1 to n-1 do  if (i mod 2=0) and (i mod 3=0) then write(g,i, ' ');  for i:=1 to N-1 do  if snt(i)=true then writeln(g,'snt:',i);  close(g);  readkey;  end.