Cho tệp văn bản 'IN.PAS' có n + 1 dòng
- Dòng đầu tiên chứa số nguyên n là chỉ số phần tử
- n dòng tiếp theo mỗi dòng chưa 1 số nguyên
Viết chương trình sử dụng để đọc và tính tổng các số nguyên lẻ trong n số nguyên đó .
Viết chương trình đọc từ tệp văn bản 'INPUT.TXT' 2 dòng
Dòng đầu tiên chứa số nguyên n là chỉ số phần tử
Dòng tiếp theo chứa n số nguyên, các số cách nhau 1 khoảng cách và không có kí hiệu xuống dòng
Tính và in ra màn hình tích các số lẻ đọc được trong n số đó
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
Viết chương trình C++ sử dụng các hàm và thủ tục xây dựng ở trên để giải bài toán:
Cho tệp dữ liệu TAMGIAC.DAT có cấu trúc như sau:
- Dòng đầu tiên chứa số N;
- N dòng tiếp theo, mỗi dòng chứa 6 số thực xA, yA, xB, yB, xC, yC là tọa độ 3 đỉnh A(xA, yA), B(xB, yB), C(xC, yC) của tam giác ABC
Hãy nhập dữ liệu từ tệpđã cho và trong số N tam giác đó, đưa ra tệp TAMGIAC.OUT gồm 3 dòng:
- Dòng đầu tiên là số lượng tam giác đều;
- Dòng thứ 2 là số lượng tam giác cân (nhưng không là đều);
- Dòng thứ 3 là số lượng tam giác vuông.
(Viet chuong trinh C++ chu khong phai Pascal a )
Viết chương trình sử dụng các hàm và thủ tục xây dựng ở trên để giải bài toán:
Cho tệp dữ liệu TAMGIAC.DAT có cấu trúc như sau:
- Dòng đầu tiên chứa số N;
- N dòng tiếp theo, mỗi dòng chứa 6 số thực xA, yA, xB, yB, xC, yC là tọa độ 3 đỉnh A(xA, yA), B(xB, yB), C(xC, yC) của tam giác ABC
Hãy nhập dữ liệu từ tệpđã cho và trong số N tam giác đó, đưa ra tệp TAMGIAC.OUT gồm 3 dòng:
- Dòng đầu tiên là số lượng tam giác đều;
- Dòng thứ 2 là số lượng tam giác cân (nhưng không là đều);
- Dòng thứ 3 là số lượng tam giác vuông.
const fi='tamgiac.dat'
fo='tamgiac.out'
var f1,f2:text;
a,b,c,d,e,f:array[1..100]of integer;
i,n,dem1,dem2,dem3:integer;
ab,bc,ac:real;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,a[i],b[i],c[i],d[i],e[i],f[i]);
dem1:=0;
dem2:=0;
dem3:=0;
for i:=1 to n do
begin
ab:=sqrt(sqr(a[i]-c[i])+sqr(b[i]-d[i]));
ac:=sqrt(sqr(a[i]-e[i])+sqr(b[i]-f[i]));
bc:=sqrt(sqr(c[i]-e[i])+sqr(d[i]-f[i]));
if (ab>0) and (ac>0) and (bc>0) and (ab+ac>bc) and (ab+bc>ac) and
(ac+bc>ab) then
begin
if (ab=ac) or (ac=bc) then inc(dem1);
if ((ab=ac) and (ab<>bc) and (ac<>bc)) then inc(dem2);
if ((ac=bc) and (bc<>ab) and (ac<>ab)) then inc(dem2);
if ((ac=bc) and (ac<>ab) and (bc<>ab)) then inc(dem2);
if sqr(ab)=sqr(ac)+sqr(bc) then inc(dem3);
if sqr(ac)=sqr(bc)+sqr(ab) then inc(dem3);
if sqr(bc)=sqr(ab)+sqr(ac) then inc(dem3);
end;
end;
writeln(f2,dem1);
writeln(f2,dem2);
writeln(f2,dem3);
close(f1);
close(f2);
end.
Cho tệp văn bản DAYSO.INP có cấu trúc:
+ Dòng 1: Ghi số nguyên dương N (0<N<=100)
+ Dòng 2: Ghi dãy gồm n số nguyên Ai (-30000<=Ai<=30000).
Yêu cầu: Viết chương trình đọc dữ liệu từ tệp trên và thực hiện các công việc sau:
a) Tính tổng các số ở dòng 2, ghi kết quả vào tệp TONG.OUT theo cấu trúc:
+ Dòng 1: Ghi số nguyên S là tổng tìm được
b) Tính tổng các số dương ở dòng 2, ghi kết quả vào tệp TD.OUT theo cấu trúc:
+ Dòng 1: Ghi số nguyên S là tổng các số dương tìm được
c) Đếm số lượng các số chẵn ở dòng 2, ghi kết quả vào tệp SOCHAN.OUT theo cấu trúc:
+ Dòng 1: Ghi số nguyên k là số lượng số chẵn
+ Dòng 2: Ghi các số chẵn tìm được, các số ghi cách nhau 1 dấu cách trống.
d) Đếm số lượng các số âm chẵn ở dòng 2, ghi kết quả vào tệp SOAMCHAN.OUT theo cấu trúc:
+ Dòng 1: Ghi số nguyên k là số lượng số âm chẵn
+ Dòng 2: Ghi các số âm chẵn tìm được, các số ghi cách nhau 1 dấu cách trống.
e) Sắp xếp các số ở dòng 2 để được dãy không giảm, ghi kết quả vào tệp SAPXEP.OUT theo cấu trúc:
+ Dòng 1: Ghi dãy số đã được sắp xếp, các số ghi cách nhau 1 dấu cách trống.
f) Đếm số lượng các số nguyên tố ở dòng 2, ghi kết quả vào tệp NTO.OUT theo cấu trúc:
+ Dòng 1: Ghi số nguyên k là số lượng số nguyên tố
+ Dòng 2: Ghi các số nguyên tố tìm được, các số ghi cách nhau 1 dấu cách trống.
HƠI DÀI NHMA MONG MẤY BẠN GIÚP CHỨ MÌNH CHỊU R
Câu 7: Viết chương trình đọc file input.txt, file được bố trí như sau:
- Dòng đầu tiên ghi số nguyên n(1<n<100) là số phần tử của file
- n dòng kế tiếp, mỗi dòng là một số nguyên
ghi ra flie output.txt dãy giảm liên tiếp dài nhất.
- Dòng đầu là số phần tử của dãy
- Dòng 2 là dãy các phần tử tăng dài nhất
Câu 8: Viết chương trình đọc file input.txt, file được bố trí như sau:
- Dòng đầu tiên ghi số nguyên n(1<n<100) là số phần tử của file
- n dòng kế tiếp, mỗi dòng là một số nguyên
ghi ra flie output.txt dãy các số nguyên tố liên tiếp dài nhất liên tiếp dài nhất.
- Dòng đầu là số phần tử của dãy
Dòng 2 là dãy các phần tử tăng dài nhất
Câu 7: Viết chương trình đọc file input.txt, file được bố trí như sau:
- Dòng đầu tiên ghi số nguyên n(1<n<100) là số phần tử của file
- n dòng kế tiếp, mỗi dòng là một số nguyên
ghi ra flie output.txt dãy giảm liên tiếp dài nhất.
- Dòng đầu là số phần tử của dãy
- Dòng 2 là dãy các phần tử tăng dài nhất
Câu 8: Viết chương trình đọc file input.txt, file được bố trí như sau:
- Dòng đầu tiên ghi số nguyên n(1<n<100) là số phần tử của file
- n dòng kế tiếp, mỗi dòng là một số nguyên
ghi ra flie output.txt dãy các số nguyên tố liên tiếp dài nhất liên tiếp dài nhất.
- Dòng đầu là số phần tử của dãy
Dòng 2 là dãy các phần tử tăng dài nhất
1. Viết chương trình tạo tệp baitap.txt trong đó dòng đầu tiên n là số lượng các số nguyên, dòng thứ 2 là n số nguyên cách nhau 2 kí tự trắng được nhập từ bàn phím (N<=100)
2.Viết chương trình tìm số nguyên lớn nhất trong n số nguyên đã có trong tệp baitap.txt và ghi kết quả vào tệp solonnhat.txt
Mong mọi người giúp mình giải sớm =(((
Câu 2:
uses crt;
var a,b:integer;
{-----------------chuong-trinh-con-------------------}
function ucln(x,y:integer):integer;
var i,uc:integer;
begin
if x<y then
begin
uc:=1;
for i:=1 to x do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end
else begin
uc:=1;
for i:=1 to y do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end;
ucln:=uc;
end;
{--------------------------chuong-trinh-chinh------------------------}
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
writeln(a,'/',b,'=',a div ucln(a,b),'/',b div ucln(a,b));
readln;
end.
Câu 1:
const fi='songuyen.inp'
fo='tong.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
n:=n+1;
read(f1,a[n]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
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.