giúp mk vs ạ mai mk thi r
Cho tệp so.txt có giá trị sau: 3 4 5 9 10 -5 9. Em hãy viết chương trình đọc tệp so.txt sau đó thực hiện các yêu cầu sau rồi ghi vào tệp kq.txt
- Tính tổng các số chẵn
- Tính tổng các số lẻ
- Tính tổng các số chia hết cho 3
AI GIÚP EM NHANH VỚI Ạ CHIỀU EM THI RỒI
cho tệp SO.TXT gồm nhiều số nguyên viết chương trình đọc dữ liệu từ tệp SO.TXT và lưu vào máy nguyên A
uses crt;
const fi='so.txt'
var f1:text;
a:array[1..100]of integer;
n,i:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
for i:=1 to n do
write(a[i]:4);
close(f1);
readln;
end.
viết chương trình đọc dữ liệu tệp SO.TXT sau đó ghi tệp "ketqua.TXT,rồi in ra màn hình
viết chương trình nhập 2 số x,y từ bàn phím, tính tổng, hiệu, tích, thương của 2 số và ghi kết quả vào tệp 'KQ.TXT'
#include <bits/stdc++.h>
using namespace std;
long long x,y;
int main()
{
cin>>x>>y;
freopen("kq.txt","w",stdout);
cout<<x+y<<endl;
cout<<x-y<<endl;
cout<<x*y<<endl;
cout<<fixed<<setprecision(2)<<(x*1.0)/(y*1.0);
return 0;
}
cho tệp so.txt gồm các số nguyên viết chương trình đọc dữ liệu từ tệp so.txt và in ra màn hình các số chẵn
uses crt;
const fi='so.txt';
var f1:text;
a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
n:=0;
while not eof(f1) do
begin
n:=n+1;
read(f1,a[n]);
end;
for i:=1 to n do
if a[i] mod 2=0 then write(a[i],' ');
close(f1);
readln;
end.
viết chương trình tạo một tệp văn bản có tên songuyen.txt trong ổ đĩa C và ghi vào tệp các số nguyên từ 1 đến 20. Sau đó đọc các số nguyên từ tệp và in ra màn hình
#include <bits/stdc++.h>
using namespace std;
long long i,a[100],n;
int main()
{
freopen("songuyen.txt","r",stdin);
n=20;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}
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.
Cho 1 tệp có tên là mang.txt viết chương trình đọc dữ liệu từ tệp sau đó tính tổng các giá trị đọc được ghi vào tệp tong.txt
const fi='mang.txt'
fo='tong.txt'
var f1,f2:text;
a:array[1..100]of integer;
n,i,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewriteln(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];
writeln(f2,t);
close(f1);
close(f2);
end.
Viết chương trình đọc từ tệp Dữ liệu.int chứa 2 số nguyên bất kì . Tính và ghi kết quả vào tệp Kết quả.out 2 dòng , dòng đầu ghi giá trị tổng 2 số , dòng thứ 2 ghi giá trị trung bình của 2 số đó
#include <bits/stdc++.h>
using namespace std;
long long a,b;
double tb;
int main()
{
freopen("dulieu.inp","r",stdin);
freopen("ketqua.out","w",stdout);
cin>>a>>b;
cout<<a<<" "<<b;
cout<<fixed<<setprecision(2)<<(a*1.0+b*1.0)/(2*1.0);
return 0;
}