Cho tệp 'input.txt' gồm nhiều dòng, mỗi dòng chứa từng cặp số nguyên a,b là hệ số của phương trình bâc nhất ax+b=0.Viết phương trình đọc các số nguyên từ tệp dữ liệu trên, tính và ghi vào tệp 'output.txt' nghiệm của ptb 1
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
Bài 1. Cho tệp văn bản input.txt gồm nhiều dòng. dòng đầu tiên ghi số nguyên dương N, N dòng tiếp theo, mỗi dòng ghi một số nguyên không lớn hơn 10000. a. Đọc dữ liệu từ tệp, đếm xem có bao nhiêu số dương chẵn. b. Đọc dữ liệu từ tệp, sắp xếp N số theo thứ tự tăng dần rồi ghi kết quả vào tệp output.txt. Ai biết làm giúp mk vớii
Cho tệp input.txt gồm nhiều dòng.Mỗi dòng là một mảng 6 số nguyên. Viết chương trình đọc dữ liệu từ tệp input.txt.Tính tổng các phân tử là bội của 2 và 3 .Kết quả xuất ra tệp output.txt
const fi='dulieu.txt'
fo='ketqua.txt'
var f1,f2:text;
a,b,c,d:array[1..100]of integer;
i,n,dem,dem1: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;
dem:=0;
dem1:=0;
for i:=1 to n do
if a[i]>b[i] then
begin
inc(dem);
inc(dem1);
c[dem]:=a[i];
d[dem]:=b[i];
end
else begin
inc(dem);
inc(dem1);
c[dem]:=b[i];
d[dem]:=a[i];
end;
for i:=1 to dem do
write(f2,c[i]:4);
writeln(f2);
for i:=1 to dem1 do
write(f2,d[i]:4);
close(f1);
close(f2);
end.
Viết chương trình và sử dụng chương trình con đọc dữ liệu từ tệp input.txt chứa dãy số nguyên trên một dòng. Các số cách nhau một khoảng trắng
Tính tổng dãy số trong tập input.txt rồi ghi kết quả tổng này vào tập output.txt
Giúp em với ạ. Em cảm ơn
const fi='input.txt'
fo='output.txt'
var f1,f2:text;
a: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
inc(n);
read(f1,a[n]);
end;
t:=0;
for i:=1 to n do t:=t+a[i];
write(f2,t);
close(f1);
close(f2);
end.
tệp xau.inp gồm các dòng kí tự, mỗi dòng không vượt quá 255 kí tự. viết chương trình đọc dữ liệu từ tệp xau.inp. đếm số kí tự là chữ'a'. ghi kết quả ra tệp xau.out chứa số nguyên duy nhất là số lượng kí tự'a' có trong tệp xau.inp
#include <bits/stdc++.h>
using namespace std;
string st;
int d,i,dem;
int main()
{
freopen("xau.inp","r",stdin);
freopen("xau.out","w",stdout);
cin>>st;
d=st.length();
dem=0;
for (i=0; i<=d-1; i++)
if (st[i]=='a') dem++;
cout<<dem;
return 0;
}
CHo tệp DULIEU TXT gồm nhiều dòng mỗi dòng gồm 2 số nguyên x và y. Đọc dữ liệu từ tệp vào ghi ra tệp KETQUA TXT số nhỏ hơn trong 2 số,mỗi số ghi trên 1 dòng.
const fi='dulieu.txt'
fo='ketqua.txt'
var f1,f2:text;
a,b:array[1..100]of integer;
n,i: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
if (a[i]<b[i]) then writeln(f2,a[i])
else writeln(f2,b[i]);
end;
close(f1);
close(f2);
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 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.