Viết chương trình nhập dữ liệu từ tệp Dulieu.txt chứa các số nguyên. Tính tổng giá trị các số có trong tệp và xuất kết quả ra màn hình
cho tệp Dulieu.txt gồm nhiều dòng, mỗi dòng chứa 2 số nguyên. Viết chương trình đọc dữ liệu từ tệp Dulieu.txt rồi tìm GTNN của mỗi dòng, rồi hiển thị ra màn hình.
uses crt;
const fi='dulieu.txt'
var f1:text;
a,b:array[1..100]of integer;
i,n:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
n:=0;
while not eof(f1) do
begin
inc(n);
readln(f1,a[n],b[n]);
end;
for i:=1 to n do
begin
if a[i]<b[i] then writeln(a[i])
else writeln(b[i]);
end;
readln;
end.
cho tệp songuyen.inp chứa dãy các số nguyên ( mỗi số cách nhau một dấu cách). Đọc dữ liệu từ tệp đã cho và
a) Tính tổng các số lẻ trong tệp và đưa kết quả lên màn hình.
b) tính tổng các số lẻ trong tệp và ghi kết quả vào tệp songuyen2
c) đưa ra màn hình các số lẻ trong tệp
uses crt;
const fi='songuyen.inp'
fo='songuyen2.out'
var a:array[1..100]of integer;
i,n,t1:integer;
f1,f2:text;
begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
t1:=0;
for i:=1 to n do if a[i] mod 2<>0 then t1:=t1+a[i];
writeln(t1);
writeln(f2,t1);
for i:=1 to n do
if a[i] mod 2<>0 then write(a[i]:4);
close(f1);
close(f2);
readln;
end.
Viết chương trình đọc 2 số thực a, b từ tệp 'DULIEU.DAT' ( Tệp 'DULIEU.DAT' có nhiều dòng dữ liệu mỗi dòng chứa hai số thực). tính chu vi P và diện tích S hình chữ nhật và xuất kết quả ra màn hình. ( yêu cầu viết chương trình đọc một dòng dữ liệu đầu tiên trong tệp 'DULIEU.DAT'
uses crt;
const fi='dulieu.dat'
var f1:text;
a,b,p,s:array[1..100]of real;
i,n:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
n:=0;
while not eof(f1) do
begin
n:=n+1;
readln(a[n],b[n]);
end;
for i:=1 to n do
begin
p[i]:=(a[i]+b[i])/2;
s[i]:=a[i]*b[i];
end;
for i:=1 to n do
writeln(p[i]:4:2,' ',s[i]:4:2);
close(f1);
readln;
end.
giả sử tệp "Dulieu.txt" có cấu trúc: Dòng 1 ghi 1 số nguyên N kiểu int; dòng 2 trở đi ghi dãy số thực A1, A2, ..., An. Yêu cầu đọc dữ liệu từ tệp, tính tổng các giá trị của dãy rồi xuất ra màn hình
uses crt;
const fi='dulieu.txt'
var f1:text;
a:array[1..100]of real;
t:real;
i,n:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
t:=0;
for i:=1 to n do t:=t+a[i];
writeln(t);
close(f1);
readln;
end.
Viết chương trình cho máy tính đọc từ tệp DAYSO.txt gồm các số nguyên có ít nhất 2 dòng
Tính tổng cấc số có trong tệp DAYSO.txt, ghi kết quả ra màn hình và tệp KETQUA.txt
Tính tổng và trung bình cộng các số chẵn trong tệp dayso.txt, ghi các kết quả vào tệp KETQUA.txt
Uses crt;
var f1,f2:text;
i,n,tong,tongchan,dem:integer;
tb:real;
Begin
clrscr;
Assign(f1,'DAYSO.txt');
Assign(f2,'KETQUA.txt');
reset(f1);dem:=0;tong:=0;tongchan:=0;
While Not EOF(f1) do
Begin
read(f1,i);
inc(tong,i);
If i mod 2 = 0 then
begin
inc(dem);
inc(tongchan,i);
end;
End;
tb:=tongchan/dem;
close(f1);
rewrite(f2);
writeln(f2,tong);
writeln(f2,tongchan);
writeln(f2,tb:0:2);
close(f2);
write(tong);
readln;
End.
Viết chương trình đọc dữ liệu từ tệp input.bass chứa hai số nguyên dương lần lượt là độ lớn của các cạnh ab của hình chữ nhật ABCD tính chu vi diện tích của hình chữ nhật trên a/ in kết quả ra màn hình b/ luôn kết quả vào tệp output. pass
Viết chương trình: Đọc từ tệp “DULIEU.TXT” 2 số nguyên M và N (M < N) Tính tổng các số chẵn trong phạm vi từ M đến N Ghi kết quả ra tệp “KETQUA.TXT”.
const fi='dulieu.txt'
fo='ketqua.txt'
var f1,f2:text;
m,n,i,t: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=0 then t:=t+i;
writeln(f2,t);
close(f1);
close(f2);
end.
Viết chương trình:
Đọc từ tệp “DULIEU.TXT” 2 số nguyên M và N (M < N)
Tính tổng các số chẵn trong phạm vi từ M đến N
Ghi kết quả ra tệp “KETQUA.TXT”.
Var f1, f2: text;
Tong, m, n, i: integer;
Begin
assign(f1, ‘DULIEU.TXT’);
reset(f1);
assign(f2, ‘KETQUA’);
rewrite(f2);
Tong;= 0;
read(f1, m, n);
for i:= m to n do
if i mod 2 = 0 then Tong:= Tong+i;
write(f2, Tong);
close(f1);
close(f2);
End.
Viết chương trình:
Đọc từ tệp “DULIEU.TXT” 2 số nguyên M và N (M < N)
Tính tổng các số lẻ trong phạm vi từ M đến N
Ghi kết quả ra tệp “KETQUA.TXT”.
Var f1, f2: text;
Tong, m, n, i: integer;
Begin
assign(f1, ‘DULIEU.TXT’);
reset(f1);
assign(f2, ‘KETQUA’);
rewrite(f2);
Tong;= 0;
read(f1, m, n);
for i:= m to n do
if i mod 2 = 1 then Tong:= Tong+i;
write(f2, Tong);
close(f1);
close(f2);
End.