Cho tệp văn bản tepA.txt mỗi dòng chứa một số nguyên. Hãy lập trình đọc lần lượt từng số nguyên trong tệp tepA.txt, tính trung bình các số đó và ghi kết quả vào tệp tep2.txt
Giúp e với ạ. E cảm ơn
Cho 2 tệp văn bản nguyen1.TXT , nguyen2.TXT . Mỗi dòng của 2 tệp chứa 1 số nguyên . Hãy lập trình tạo tệp 1 văn bản chứa nguyen1.TXT , nguyen2TXT . Những dòng đầu tiên là các dòng của nguyen1.TXT , còn lại là nguyen2.TXT
const fi1='nguyen1.txt'
fi2='nguyen2.txt'
fo='nguyen.txt'
var f1,f2,f3:text;
a,b:array[1..100]of integer;
n,m,i:integer;
begin
assign(f1,fi1); reset(f1);
assign(f2,fi2); reset(f2);
assign(f3,fo); rewrite(f3);
n:=0;
while not eof(f1) do
begin
inc(n);
readln(f1,a[n]);
end;
m:=0;
while not eof(f2) do
begin
m:=m+1;
readln(f1,b[m]);
end;
for i:=1 to n do
writeln(f3,a[i]);
for i:=1 to m do
writeln(f3,b[i]);
close(f1);
close(f2);
close(f3);
end.
Cho 50 số nguyên được ghi trong tệp 'NUMBER.TXT' (dữ liệu được ghi trên một dòng). Hãy viết chương trình đọc các số nguyên chẵn trong 50 số nguyên đó và ghi ra tệp 'KQ.TXT' GIÚP E VỚI Ạ. E ĐANG CẦN GẤPPPPP
Cho tệp DATA.INP mỗi dòng chứa 1 số nguyên . Hãy viết chương trình pascal tính trung bình cộng các số kết quả ghi vào tệp KQ.OUT
const fi='data.inp'
fo='kq.out'
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 eoln(f1) do
begin
inc(n);
read(f1,a[n]);
end;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,t/n:4:2);
close(f1);
close(f2);
end.
const fi='input.txt'
fo='chiahet.txt'
var f1,f2:text;
a:array[1..100]of integer;
i,n,dem:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
n:=0;
while not eoln(f1) do
begin
inc(n);
read(f1,a[n]);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 3=0 then inc(dem);
writeln(f2,dem);
close(f1);
close(f2);
end.
Cho tệp văn bản tbc.inp chứa 4 số nguyên a,b,c,d . Viết phương trình đọc 4 số nguyên từ tệp tbc.inp và tính trung bình cộng của 4 số nguyên đó. Kết quả thu được cho vào tệp tbc.out
code c++:
#include <iostream>
using namespace std;
int main()
{
freopen("tbc.inp","r",stdin);
freopen("tbc.out","w",stdout);
int a,b,c,d;
cin>>a>>b>>c>>d;
float r;
r=(a+b+c+d)/4;
cout<<r<<endl;
return 0;
}
code pascal:
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
Cho tệp văn bản có tên DATA2.TXT chứa một xâu bất kì không quá 255 kí tự gồm các chữ và số. Viết chương trình đọc xâu kí tự S từ từ tệp DATA2.TXT sau đó ghi dữ liệu là các thông tin sau vào tệp KQ2.TXT:
- Dòng 1: Số lần xuất hiện của kí tự "k" trong xâu?
- Dòng 2: Số lượng kí tự là số xuất hiện trong S (giữ nguyên thứ tự xuất hiện)?