Bài 14: Kiểu dữ liệu tệp

Nguyễn Thi Thư
Xem chi tiết
Minh Lệ
15 tháng 5 2023 lúc 19:54

Program HOC24;

var i,n: integer;

t: longint;

f1,f2: text;

begin

assign(f1,'BAI1.INP');

reset(f1);

read(f1,n);

t:=0;

for i:=1 to n do if i mod 2=0 then t:=t+i;

close(f1);

assign(f2,'BAI1.OUT');

rewrite(f2);

write(f2,t);

close(f2);

end.

Bình luận (0)
Phạm Hồng Nguyên
Xem chi tiết
A8_ Võ Thị Thương
Xem chi tiết
hoàng đức
Xem chi tiết
Minh Trí Đoàn
Xem chi tiết
Phía sau một cô gái
18 tháng 2 2023 lúc 14:54

with open('songuyen.txt', 'r') as f:

     with open('ketqua.txt', 'w') as g:

          for line in f:

               numbers = line.split()

               for number in numbers:

                    if int(number) % 2 == 0:

                         g.write(number + '\n')

      
Bình luận (0)
thu huyền
Xem chi tiết
Lan Phuong
Xem chi tiết
Nguyễn Lê Phước Thịnh
20 tháng 4 2022 lúc 16:53

const fi='demxau.inp',

fo='demxau.out'

var f1,f2:text;

st:string;

d,i,dem:integer;

begin

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

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

readln(f1,st);

d:=length(st);

dem:=0;

for i:=1 to d do 

  if st[i]=' ' then dem:=dem+1;

writeln(f2,dem+1);

close(f1);

close(f2);

end.

Bình luận (0)
Mang Phạm
Xem chi tiết