K
Khách

Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.

Bài 1:

const fi='input.txt';
fo='ketqua.txt';
var f1,f2:text;
a,b:array[1..100]of integer;
i,n,t: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],b[n]);
end;
for i:=1 to n do
begin
t:=a[i]+b[i];
write(f2,t:4);
end;
close(f1);
close(f2);
end.

Bài 2:

const fi='input.txt';
fo='ketqua.txt';
var f1,f2:text;
d,r:array[1..100]of integer;
i,n:integer;
s:longint;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
n:=0;
while not eof(f1) do
begin
n:=n+1;
readln(f1,d[n],r[n]);
end;
for i:=1 to n do
begin
s:=d[i]*r[i];
write(f2,s:4);
end;
close(f1);
close(f2);
end.

10 tháng 5 2023

with open('XAU.INP', 'r') as input_file, open('XAU.OUT', 'w') as output_file:

        for line in input_file:

                length = len(line.strip())

                output_file.write(f'{length}\n')

3 tháng 3 2021

a)

PROGRAM BAI1a;

VAR N, Tle, Tchan: integer;

BEGIN

          Write ('Nhap N =');

          Readln (N);

          If (N mod 2) = 0 Then

          Tle := N*((N - 2)/2 + 1)/2;

          Tchan := (N + 2)*((N - 2)/2 + 1)/2;

          If (N mod 2) = 1 Then

          Tle := (N + 1)*((N-1)/2 +1)/2;

          Tchan := (N + 1)*((N - 3)/2 + 1)/2;

          WRITELN ('Sle =', Sle, 'Schan =', Schan);

          READLN;

          END.

uses crt;

const fi='tep.txt';

var f1:text;

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

i,n,kt,j,dem:integer;

begin

clrscr;

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

n:=0;

while not eof(f1) do 

  begin

n:=n+1;

readln(f1,a[n]);

end;

dem:=0;

for i:=1 to n do 

  if a[i]>1 then 

begin

kt:=0;

for j:=2 to a[i]-1 do 

  if a[i] mod j=0 then kt:=1;

if kt=0 then inc(dem);

end;

writeln(dem);

close(f1);

readln;

end.

Câu 2: 

uses crt;

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

i,n,min,dem1,dem2,t1,t2:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

max:=a[1];

for i:=1 to n do 

if max<a[i] then max:=a[i];

writeln('Gia tri lon nhat la: ',max);

dem1:=0;

dem2:=0;

t1:=0;

t2:=0;

for i:=1 to n do 

begin

if a[i] mod 2=0 then 

begin

inc(dem1);

t1:=t1+a[i];

end

else begin

inc(dem2);

t2:=t2+a[i];

end;

end;

writeln('So so chan la: ',dem1);

writeln('So so le la: ',dem2);

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

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

readln;

end.

Câu 1: 

const fi='dulieu.inp';

fo='ketqua.out';

var f1,f2:text;

m,n,t,i:integer;

begin

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

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

readln(f1,m,n);

t:=0;

for i:=m to n do 

  if i mod 2=1 then t:=t+i;

writeln(f2,t);

close(f1);

close(f2);

end.

const fi='tong.inp';

fo='tong.out';

var f1,f2:text;

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

n,i,t:integer;

begin

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

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

readln(f1,n);

for i:=1 to n do 

  read(f1,a[i]);

t:=0;

for i:=1 to n do 

  t:=t+a[i];

writeln(f2,t);

close(f1);

close(f2);

end.