Tệp và thao tác với tệp

Quyền
Xem chi tiết
Quyền
4 tháng 5 2021 lúc 20:55

Uses crt; Var f1,f2:text; i,n,max:integer; a:array[1..100] of integer; Begin Assign(f1,'baitap.txt');reset(f1); Assign(f2,'solonnhat.txt');rewrite(f2); While not eof(f1) do Begin Read(f1,n,a[i]); Max:=a[1]; For i:=2 to n do if a[i]>max then max:=a[i]; End; Writeln(f2,'solonnhatla:',max); Close(f1);close(f2); End.

Bình luận (0)
Quyền
4 tháng 5 2021 lúc 21:30

uses crt;
var n,max :integer;
    f1,f2:text;
begin
clrscr;
assign(f1,'baitap.txt'); reset(f1);
assign(f2,'solonhat.txt'); rewrite(f2);
max:=0;
while not eof(f1) do
  begin
  read(f1,n);
  if max <n then max:=n;
  end;
writeln('solonhatla: ',max:5);
write(f2,max);
close(f1);close(f2);
readln;
end.

Bình luận (0)
Quyền
Xem chi tiết
Nguyễn Lê Phước Thịnh
4 tháng 5 2021 lúc 11:45

uses crt;

const fi='baitap.txt'

var f1:text;

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

n,i:integer;

begin

clrscr;

assign(f1,fi); rewrite(f1);

write('Nhap n='); readln(n);

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

writeln(f1,n);

for i:=1 to n do 

  write(f1,a[i]:4);

close(f1);

readln;

end.

Bình luận (1)
Hung Do Van
Xem chi tiết
Nguyễn Lê Phước Thịnh
4 tháng 5 2021 lúc 13:03

Câu 1: 

const fi='dulieu.dat'

fo='thaythe.out'

var f1,f2:text;

a:array[1..100]of string;

n,d,i,vt:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

n:=0;

while not eof(f1) do 

  begin

n:=n+1;

readln(f1,a[n]);

end;

for i:=1 to n do 

  begin

d:=length(a[i]);

vt:=pos('anh',a[i]);

while vt<>0 do 

  begin

delete(a[i],vt,3);

insert('em',a[i],vt);

vt:=pos('anh',a[i]);

end;

end;

for i:=1 to n do 

  writeln(f2,a[i]);

close(f1);

close(f2);

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
4 tháng 5 2021 lúc 13:05

Câu 2: 

uses crt;

const fi='mang.inp'

fo='sapxep.out'

var f1,f2:text;

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

i,n,tam,j:integer;

begin

clrscr;

assign(f1,fi); rewrite(f1);

assign(f2,fo); rewrite(f2);

write('Nhap n='); readln(n);

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

for i:=1 to n do 

  write(f1,a[i]:4);

for i:=1 to n-1 do 

  for j:=i+1 to n do 

if a[i]>a[j] then

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

for i:=1 to n do 

  write(f2,a[i]:4);

close(f1);

close(f2);

end.

Bình luận (0)
Ngọc Ánh
Xem chi tiết
Nguyen Hung
3 tháng 5 2021 lúc 21:04

Uses crt;

Var i,n,tong:integer;

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

      f1,f2:text;

Begin

clrscr;

Assign(f1,'tinhtong.inp');

Assign(f2,'tinhtong.out');

tong:=0;

Reset(f1);readln(f1,n);

For i:= 1 to n do

Begin

read(f1,a[i]);

tong:=tong+a[i];

End;

close(f1);

rewrite(f2);

Writeln(f2,tong);

Readln;

End.

Bình luận (1)
Nguyen Duc Anh
Xem chi tiết
Nguyễn Lê Phước Thịnh
4 tháng 5 2021 lúc 13:42

const fi='hcn.txt'

fo='ketqua.txt'

var f1,f2:text;

a,b:array[1..100]of integer;

n:integer;

cv,dt:real;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

n:=0;

while not eof(f1) do

  begin

inc(n);

readln(f1,a[n],b[n]);

end;

for i:=1 to n do 

  begin

cv:=(a[i]+b[i])/2;

dt:=a[i]*b[i];

writeln(f2,cv:4:2,' ',dt:4:2);

end;

close(f1);

close(f2);

end.

Bình luận (0)
Phạm Thị Thu Hằng
Xem chi tiết
Nguyễn Lê Phước Thịnh
4 tháng 5 2021 lúc 13:48

uses crt;

const fi='so.txt'

var f1:text;

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

n,i:integer;

begin

clrscr;

assign(f1,fi); reset(f1);

readln(f1,n);

for i:=1 to n do  

  read(f1,a[i]);

for i:=1 to n do 

  write(a[i]:4);

close(f1);

readln;

end.

Bình luận (0)
Nguyễn Giang
Xem chi tiết
Nguyễn Lê Phước Thịnh
1 tháng 5 2021 lúc 19:39

uses crt;

const fi='mang.txt'

var a:array[1..100]of integer;

i,n,t1,t2:integer;

f1:text;
begin

clrscr;

assign(f1,fi); rewrite(f1);

write('Nhap n='); readln(n);

for i:=1 to n do 

  begin

write('A[',i,']='); readln(a[i]);

end;

t1:=0;

t2:=0;

for i:=1 to n do 

  begin

if a[i]>0 then 

begin

t1:=t1+a[i];

end;

if a[i]<0 then

begin

t2:=t2+a[i];

end;

end;

writeln(f1,'Tong cac so duong la: ',t1);

writeln(f1,'Tong cac so am la: ',t2);

if abs(t1)>abs(t2) then writeln(f1,'Gia tri tuyet doi cua ',t1,' lon hon gia tri tuyet doi cua ',t2)

else if abs(t1)<abs(t2) then writeln(f1,'Gia tri tuyet doi cua ',t2,' lon hon gia tri tuyet doi cua ',t1)

else writeln(f1,'Gia tri tuyet doi cua ',t1,' bang gia tri tuyet doi cua ',t2);

close(f1);

end.

Bình luận (0)
Minhh Minhh
Xem chi tiết