Cho tệp ăn.txt chứa dãy các số nguyên liên tiếp viết cách nhau 1 dấu cách .viết CT đọc dữ liệu từ tệp txt tính tổng các số chẵn và tổng các số lẻ ghi kết quả vào tập kq.txt trên 2 dòng
tệp data inp chứa một dãy số gồm 10 số cách nhau bởi dấu cách em hãy viết chương trình đọc toàn bộ các chữ số trong tệp tính và ghi kết quả vào tệp data.out tổng các chữ số chia hết cho 5
Cho tệp SN3.INP chứa n số nguyên dương (mỗi số cách nhau một dấu cách trên một dòng). Viết chương trình đọc dữ liệu từ tệp đã cho Tính ƯCLN dãy các số nguyên dương đó và lưu kết quả vào tệp UC.OUT .
#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1000],i,n,uc;
//chuongtrinhcon
unsigned long long ucln(long long a,long long b)
{
if (b==0) return(a);
else return(ucln(b,a%b));
}
//chuongtrinhchinh
int main()
{
freopen("sn3.inp","r",stdin);
freopen("uc.out","w",stdout);
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
uc=ucln(a[1],a[2]);
for (i=3; i<=n; i++)
uc=ucln(uc,a[i]);
cout<<uc;
return 0;
}
cho tệp DataIn.txt chứa liên tiếp 24 dãy số các số nguyên dương và âm, các số trên cùng một dòng ngăn cách nhau bởi dấu cách. viết chương trình đọc các số vào chương trình pascal và tính tổng rồi ghi ra DataOut.txt
xin giúp đỡ ạ
const fi='dataln.txt'
fo='dataout.txt'
var f1,f2:text;
x,i,t:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
t:=0;
for i:=1 to 24 do
begin
read(f1,x);
t:=t+x;
end;
writeln(f2,t);
close(f1);
close(f2);
end.
cho tệp Data.txt chứa liên tiếp các số nguyên, mỗi số trên 1 dòng. viết chương trình đọc các số vào chương trình pascal và tính trùng bình cộng các số đó. ghi kết quả vào TBC.txt
const fi='data.txt'
fo='tbc.txt'
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);
n:=0;
while not eof(f1) do
begin
n:=n+1;
readln(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.
Viết chương trình đọc số liệu của dãy N số trong tệp DATA1.TXT. Sau đó ghi dữ liệu là các thông tin sau vào tệp KQ1.TXT: - Dòng 1: Tổng các số lẻ trong dãy? - Dòng 2: Danh sách các số dương chia cho 5 có trong dãy, mỗi số cách nhau 1 cách
Program HOC24;
var i,n: integer;
a: array[1..1000] of integer;
t: longint;
f1,f2: text;
const fi='DATA1.TXT'
fo='KQ1.TXT'
begin
assign(f1,fi);
assign(f2,fo);
reset(f1);
rewrite(f2);
readln(f1,n);
for i:=1 to n do read(f1,a[i]);
t:=0;
for i:=1 to n do if a[i] mod 2=0 then t:=t+a[i];
writeln(f2,t);
for i:=1 to n do if a[i] mod 5=0 then write(f2,a[i],' ');
close(f1); close(f2);
end.
Tệp "DULIEU.INP" chứa hai số nguyên dương ngăn cách nhau ít nhất một dấu cách, số trước nhỏ hơn số sau và nhỏ hơn 100.
Viết chương trình: Đọc từ tệp "DULIEU.INP" vào biến M và N (M<N). Tính tổng các số lẻ trong phạm vi từ M đến N. Ghi kết quả ra tệp "KETQUA.OUT".
#include <bits/stdc++.h>
using namespace std;
long long m,n,t,i;
int main()
{
freopen("dulieu.inp","r",stdin);
freopen("ketqua.out","w",stdout);
cin>>m>>n;
t=0;
for (i=m; i<=n; i++)
if (i%2!=0) t+=i;
cout<<t;
return 0;
}
cho tệp input txt chứa 3 số nguyên dương.viết chương trình đọc 3 số trong tệp input.txt tìm ra số có giá trị nhỏ nhất trong 3 số.kết quả ghi vào tệp output.txt
const fi='input.txt'
fo='output.txt'
var f1,f2:text;
a,b,c,max:real;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a,b,c);
min:=a;
if min>b then min:=b;
if min>c then min:=c;
writeln(f2,min);
close(f1);
close(f2);
end.
cho tệp DATA.TXT các số nguyên, các số cách nhau bởi một dấu cách.Hãy lập chương trình đếm các số lẻ. Ghi kết quả vào tệp TES.TXT.