cho tệp SONGUYEN.TXT gồm 2 dòng, dòng 1 chứa số nguyên dương n, dòng 2 chứa n số nguyên. Các số nguyên ngăn cách nhau bởi dấu cách. Viết chương trình đọc dữ liệu từ tệp SONGUYEN.TXT. Tính và đưa ra kết quả số lượng các số nguyên tố và tệp KETQUA.TXT
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
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;
}
tệp 'dữ liệu inp' chứa các số nguyên dương ngăn cách nhau bởi dấu cách và không chứa ký tự xuống dòng dọc từ tệp dữ liệu inp mỗi lần 3 số nguyên và ghi kết quả đọc được lên tệp dữ liệu .out
giả sử trên đĩa E có tệp SO.INP chứa nhiều dòng dữ liệu, mỗi dòng chứa hai số nguyên cách nhau bởi dấu cách. hãy viết chương trình đọc ra mỗi dòng dữ liệu trong tệp SO.INP, sau đó tính trung bình cộng của mỗi dòng và hiển thị kết quả trung bình cộng ra màn hình tương ứng với mỗi dòng dữ liệu? Mn giúp mik vs
uses crt;
const fi='so.inp'
var f1:text;
a,b:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
while not eof(f1) do
begin
readln(f1,a,b);
writeln((a+b)/2:4:2);
end;
close(f1);
readln;
end.
cho tệp DataIn.txt chứa liên tiếp 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='dulieu.txt'
fo='ketqua.txt'
var i,t:integer;
f1,f2:text;
a:array[1..9]of integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
t:=0;
for i:=1 to 9 do
begin
read(f1,a[i]);
t:=t+a[i];
end;
writeln(f2,t);
close(f1);
close(f2);
end.
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 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.
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.
Viết chương trình đọc từ tệp đayso.inp sang dạy sỗ A1,A2,....AN rồi thực hiện in dãy ra màn hình
- Tệp dayso.inp có cấu trúc:
+ Dòng 1: là 1 số nguyên dương N
+ Dòng 2: gồm N số nguyên ngăn cách nhau bởi 1 đấu cách
mọi người ơi giúp e với.
uses crt;
const fi='dayso.inp',
var a:array[1..100]of integer;
i,n:integer;
f1:text;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,n);
for i:=1 to n do readln(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ừ tệp input.pas (tệp có chứa 2 số nguyên cách nhau bởi dấu cách) và ghi vào tệp output.pas tích của hai số nguyên vừa đọc từ tệp input.pas
Program HOC24;
var f1,f2: text;
a,b: integer;
t: longint;
begin
assign(f1,'input.pas');
reset(f1);
assign(f2,'output.pas');
rewrite(f2);
readln(f1,a,b);
t:=a*b;
write(f2,t);
close(f1);
close(f2);
End.