Viết chương trình và sử dụng chương trình con đọc dữ liệu từ tệp input.txt chứa dãy số nguyên trên một dòng. Các số cách nhau một khoảng trắng
Tính tổng dãy số trong tập input.txt rồi ghi kết quả tổng này vào tập output.txt
Giúp em với ạ. Em cảm ơn
Cho tệp input.txt gồm nhiều dòng.Mỗi dòng là một mảng 6 số nguyên. Viết chương trình đọc dữ liệu từ tệp input.txt.Tính tổng các phân tử là bội của 2 và 3 .Kết quả xuất ra tệp output.txt
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;
}
Viết chương trình đọc từ tệp " input.txt" ( tệp " input .txt" chứa 4 số nguyên ) ghi vào tệp " output.txt" tổng 4 số nguyên trong tệp " input.txt" Tong là:10
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>a>>b>>c>>d;
cout<<a+b+c+d;
return 0;
}
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
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 một tệp có tên input.txt. tệp input chứa nhiều dòng, mỗi dòng là 3 số thực, cách nhau bởi dấu cách. Viết chương trình:
a) Tính tổng số thực trên mỗi dòng trong tệp input.txt
b) Tính trung bình cộng các số thực trên mỗi dòng trong tệp input.txt
uses crt;
const fi='input.txt'
var f1:text;
a,b,c:array[1..100]of real;
i,n:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
n:=0;
while not eof(f1) do
begin
n:=n+1;
readln(f1,a[n],b[n],c[n]);
end;
for i:=1 to n do
writeln('Tong cua dong ',i,' la: ',a[i]+b[i]+c[i]:4:2);
for i:=1 to n do
writeln('Trung binh cong cua dong ',i,' la: ',(a[i]+b[i]+c[i])/3:4:2);
close(f1);
readln;
end.
Viết chương trình đọc dữ liệu từ tệp Input.txt chứa một xâu có độ dài không quá 125 ký tự .Cho biết số lần xuất hiện của mỗi chữ cái Tiếng Anh trong xâu đã đọc được ( không phân chữ hoa thường). Ghi kết quả ra tệp Output.txt
const fi='input.txt'
fo='output.txt'
var f1,f2:text;
st:string[125];
a:array[1..125]of string;
i,d,dem,kt,j:integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,st);
d:=length(st);
dem:=1;
a[1]:=st[1];
for i:=1 to d do
begin
kt:=0;
for j:=1 to dem do
if a[j]=st[i] then kt:=1;
if kt=0 then
begin
inc(dem);
a[dem]:=st[i];
end;
end;
for i:=1 to dem do
begin
dem1:=0;
for j:=1 to d do
if a[i]=st[j] then inc(dem1);
writeln(f2,a[i],' xuat hien ',dem1,' lan');
end;
close(f1);
close(f2);
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
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ố đó