Cho một tệp có tên input.txt. tệp input chứa nhiều dòng, mỗi dòng là 3 số thực, cách nhau bởi dấu cách. Viết chương trình:
a) Tính tổng số thực trên mỗi dòng trong tệp input.txt
b) Tính trung bình cộng các số thực trên mỗi dòng trong tệp input.txt
giả sử trên đĩa E có tệp SO.INP chứa nhiều dòng dữ liệu, mỗi dòng chứa hai số nguyên cách nhau bởi dấu cách. hãy viết chương trình đọc ra mỗi dòng dữ liệu trong tệp SO.INP, sau đó tính trung bình cộng của mỗi dòng và hiển thị kết quả trung bình cộng ra màn hình tương ứng với mỗi dòng dữ liệu? Mn giúp mik vs
uses crt;
const fi='so.inp'
var f1:text;
a,b:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
while not eof(f1) do
begin
readln(f1,a,b);
writeln((a+b)/2:4:2);
end;
close(f1);
readln;
end.
Cho tệp dulieuvao.txt gồm nhiều dòng, mỗi dòng chứa 2 số nguyên a, b. Các số cách nhau bởi dấu cách. Viết chương trình đọc dữ liệu từ tệp, tính trung bình cộng và ghi kết quả ra tệp dulieura
Viết chương trình cho tệp dulieuvao.dat trong đó có chứa 5 dòng, mỗi dòng có nhiều số, mỗi số cách nhau một dấu cách. Em hãy tính tổng của mỗi dòng.
uses crt;
const fi='dulieuvao.dat'
var f1:text;
a,b,c,d,e:array[1.1.00]of integer;
n,m,d,x,v,t,t1,t2,t3,t4,t5,i:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
n:=0;
while not eoln(f1) do
begin
n:=n+1;
read(f1,a[n]);
end;
readln(f1);
m:=0;
while not eoln(f1) do
begin
inc(m);
read(f1,b[m]);
end;
readln(f1);
d:=0;
while not eoln(f1) do
begin
inc(d);
read(f1,c[d]);
end;
readln(f1);
x:=0;
while not eoln(f1) do
begin
inc(x);
read(f1,d[x]);
end;
readln(f1);
v:=0;
while not eoln(f1) do
begin
inc(v);
read(f1,e[v]);
end;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day 1 la: ',t);
t1:=0;
for i:=1 to m do
t1:=1+b[i];
writeln('Tong cua day 2 la: ',t1);
t2:=0;
for i:=1 to d do
t2:=t2+c[i];
writeln('Tong cua day 3 la: ',t2);
t3:=0;
for i:=1 to x do
t3:=t3+d[i];
writeln('Tong cua day 4 la: ',t3);
t4:=0;
for i:=1 to v do
t4:=t4+e[i];
writeln('Tong cua day 5 la: ',t4);
close(f1);
readln;
end.
Cho tệp input.txt gồm nhiều dòng , mỗi dòng chứa 1 số nguyên . Hãy ghi ra tệp soạn.txt các số nguyên âm có trong tệp input.txt, mỗi số trên 1 dòng
const fi='input.txt'
fo='soan.txt'
var f1,f2:text;
a:array[1..100]of integer;
i,n: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
if a[i]<0 then writeln(f2,a[i]:4);
close(f1);
close(f2);
end.
Cho tệp văn bản tamgiac.DAT mỗi dòng của tệp chứa 3 cặp số thực , xác định tọa độ các đỉnh tương ứng của tam giác ABC . Các số trên 1 dòng cách nhau bởi 1 dấu cách . Hãy lần lượt đọc các dòng của tệp , kiểm tra xem tam giác ABC có phải là tam giác cân hay không và đưa ra màn hình số lượng tam giác cân .
uses crt;
const fi='tamgiac.dat'
var f1:text;
a,b,c:array[1..100]of real;
n,i,j,k,dem:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
n:=0;
while not eof(f1) do
begin
inc(n);
readln(f1,a[n],b[n],c[n]);
end;
dem:=0;
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
if (i=j) and (j=k) then
begin
if (a[i]+b[j]>c[k]) and (a[i]+c[k]>b[j]) and (c[k]+b[j]>a[i]) then
begin
if (a[i]=b[j]) and (a[i]<>c[k]) and (b[j]<>c[k]) then inc(dem);
if (a[i]=c[k]) and (a[i]<>b[j]) and (c[k]<>b[j]) then inc(dem);
if (b[j]=c[k]) and (b[j]<>a[i]) and (c[k]<>a[i]) then inc(dem);
end;
end;
writeln(dem);
readln;
end.
Cho tệp SN3.INP chứa n số nguyên dương (mỗi số cách nhau một dấu cách trên một dòng). Viết chương trình đọc dữ liệu từ tệp đã cho Tính ƯCLN dãy các số nguyên dương đó và lưu kết quả vào tệp UC.OUT .
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1000],i,n,uc;
//chuongtrinhcon
unsigned long long ucln(long long a,long long b)
{
if (b==0) return(a);
else return(ucln(b,a%b));
}
//chuongtrinhchinh
int main()
{
freopen("sn3.inp","r",stdin);
freopen("uc.out","w",stdout);
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
uc=ucln(a[1],a[2]);
for (i=3; i<=n; i++)
uc=ucln(uc,a[i]);
cout<<uc;
return 0;
}
Cho tệp dulieu.inp chứa các bộ số nguyên ( mỗi bộ ghi trên 1 dòng gồm 2 số nguyên cách nhau bởi 1 kí tự trống). Vt ctrinh đọc dữ liệu trong tệp trên rồi tính tổng của mỗi bộ số nguyên, ghi các kq vào tệp tong.out( mỗi kq trên 1 dòng ). Lưu ý có sd ctrinh con
Cho tệp 'dayso.in' chứa các dãy số nguyên A1, A2....,An mỗi dãy sô nằm trên 1 dòng. Viết chương trình tính tổng theo dòng trong tệp 'dayso.in' sau đó ghi các số tổng này lên tệp 'tong.out', mỗi số ghi trên một dòng