Bài tập dữ liệu kiểu tệp tính tổng s=1+2+3+......+n với n số nguyên dương được nhập vào từ 1 têp có tên dulieu.txt đặt trên ổ đĩa D.Kết quả ghi ra tệp tong.doc lueu trên ổ đĩa D
1. Viết chương trình đọc 2 số a,b từ tệp INPUT.TXT và ghi tích của 2 số a,b đó vào tệp OUTPUT.TXT
INPUT.TXT 2 3
OUTPUT.TXT 6
2. Viết chương trình đọc 2 số a,b từ tệp DULIEU.TXT trên ổ đĩa D và ghi số lớn nhất trong 2 số a,b đó vào tệp KETQUA.TXT trên ổ đĩa D
D:\DULIEU.TXT 2 3
D:\KETQUA.TXT 3
Bài 1:
const fi='input.txt';
fo='output.txt';
var f1,f2:text;
a,b,s:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a,b);
s:=a*b;
writeln(f2,s);
close(f1);
close(f2);
end.
Bài 2:
const fi='dulieu.txt';
fo='ketqua.txt';
var f1,f2:text;
a,b:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a,b);
if a>b then writeln(f2,a)
else if b>a then writeln(f2,b)
else writeln(f2,' khong co so lon nhat trong hai so');
close(f1);
close(f2);
end.
1. Viết chương trình nhập vào dữ liệu từ file có sẵn với tên là dulieu.txt trong ổ đĩa D, mỗi lần 2 giá trị và xuất ra tổng và hiệu của 2 số vừa đọc được.
2. Viết ct nhập vào dữ liệu từ file có sẵn với tên là dulieu.txt trong ổ đĩa D, mỗi lần 3 giá trị và xuất ra kết quả 3 số đó có phải là cạnh của 1 tam giác hay k, nếu là tam giác hãy xuất ra chu vi ra file có tên kq.txt trong ổ đĩa D.
Giúp mình với ạ..thanks
Bài 1:
Program hotrotinhoc_hoc24;
const fi='dulieu.txt';
var a,b: integer;
f: text;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,a,b);
close(f);
end;
begin
ip;
writeln('Tong la : ',a+b);
write('Hieu la : ',a-b);
readln
end.
Program hotrotinhoc_hoc24;
const fi='dulieu.txt';
fo='ketqua.txt';
var f: text;
a,b,c : integer;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,a,b,c);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
if (a+b>c) and (a+c>b) and (b+c>a) then write(f,a+b+c);
close(f);
end;
begin
ip;
out;
end.
Lập trình đọc số nguyên dương N vào tệp có tên ‘Dulieu.txt’ Tính tổng các số chẵn từ 1 đến N, kết quả ghi ra tệp ‘ Uot.txt’ Mọi người giúp em gấp với ạ!!!!!! Em cảm ơn!
#include <bits/stdc++.h>
using namespace std;
long long n,i,t;
int main()
{
freopen("dulieu.txt","r",stdin);
freopen("uot.txt","w",stdout);
cin>>n;
t=0;
for (i=1; i<=n; i++)
if (i%2==0) t+=i;
cout<<t;
return 0;
}
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;
}
Thực hành tìm hiểu máy tính em đang sử dụng và cho biết:
a) Tên các ổ đĩa trên máy tính là gì?
b) Kể tên một số thư mục, tệp có trên ổ đĩa (D:).
c) Mở một thư mục trong ổ đĩa (D:) và nêu tên một số thư mục con, tệp trong thư mục đó.
a) Tên các ổ đĩa trên máy tính: ổ (D:), ổ (C:), ổ (E:).
b) Các em tự xem và trả lời.
Gợi ý:
Tên một số thư mục, tệp có trên ổ đĩa (D:):
Thư mục: Sach, giai tri, Program Files.
Tệp: tin 3.docx
c) Các em tham khảo các bước:
Mở thư mục sach trong ổ đĩa (D:) thư mục con là sach giao khoa và sach tham khoa
Tệp: Tin nang cao.docx
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 tính tổng của n số nguyên có trong tệp Tong.inv. đưa giá trị tìm được ra tệp Tong.out. Dữ liệu vào gồm hai dòng dòng 1 ghi số nguyen dương n dòng 2 ghi n số nguyên dương dữ liệu ra một số nguyên duy nhất là tổng tìm được
const fi='tong.inp'
fo='tong.out'
var f1,f2:text;
a:array[1..100]of integer;
n,i,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
read(f1,a[i]);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
Giả sử có tệp SONGUYEN.TXT chứa các số nguyên bất kì (giữa các số cách nhau một dấu cách).Viết chương trình đọc dữ liệu từ tệp trên, tính tổng các số lẻ và ghi kết quả vào tệp SOLE.TXT( các tệp được lưu ở ổ đĩa C)
const fi='songuyen.txt';
fo='sole.txt';
var f1,f2:text;
n,i,t:integer;
a:array[1..100]of 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
if a[i] mod 2=1 then t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
Viết chương trình nhập vào 3 số nguyên , sau đó ghi 3 số nguyên vừa nhập đó vào tệp Dulieu.txt ở ổ D:\
uses crt;
const fi='dulieu.txt'
var f1:text;
a,b,c:integer;
begin
clrscr;
assign(f1,fi); rewrite(f1);
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
write('Nhap c='); readln(c);
writeln(f1,a);
writeln(f1,b);
writeln(f1,c);
close(f1);
end.