cho tệp SONGUYEN.INP chứa 3 số nguyên a,b,c có kiểu dữ liệu kiểu long long. tìm giá trị lớn nhất của 3 số trên và ghi kết quả vào tệp lonnhat.out
cho tệp songuyen.inp chứa dãy các số nguyên ( mỗi số cách nhau một dấu cách). Đọc dữ liệu từ tệp đã cho và
a) Tính tổng các số lẻ trong tệp và đưa kết quả lên màn hình.
b) tính tổng các số lẻ trong tệp và ghi kết quả vào tệp songuyen2
c) đưa ra màn hình các số lẻ trong tệp
uses crt;
const fi='songuyen.inp'
fo='songuyen2.out'
var a:array[1..100]of integer;
i,n,t1:integer;
f1,f2:text;
begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
t1:=0;
for i:=1 to n do if a[i] mod 2<>0 then t1:=t1+a[i];
writeln(t1);
writeln(f2,t1);
for i:=1 to n do
if a[i] mod 2<>0 then write(a[i]:4);
close(f1);
close(f2);
readln;
end.
Đọc dữ liệu từ tệp DL.Dat có chứa các chữ số nguyên. Đếm trong tệp có bao nhiêu số nguyên tố. Các kết quả ghi vào tệp KQ.Dat (C++)
#include <bits/stdc++.h>
using namespace std;
long long n,i,x;
//chuongtrinhcon
bool ktnt(long long x)
{
if (x<2) return false;
for (int i=2; i*i<=x; i++)
if (x%i==0) return(false);
return true;
}
//chuongtrinhchinh
int main()
{
freopen("dl.dat","r",stdin);
freopen("kq.dat","w",stdout);
cin>>n;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (ktnt(x)) dem++;
}
cout<<dem;
return 0;
}
Cho tệp INPUT.INP có chứa 2 số nguyên a và b. Viết chương trình đọc dữ liệu từ tệp INPUT.INP và ghi vào tệp OUTPUT.OUT số nhỏ nhất của 2 số nguyên này
const fi='input.inp'
fo='output.out'
var a,b:integer;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,a,b);
if a<b then writeln(f2,a)
else writeln(f2,b);
close(f1);
close(f2);
end.
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
Viết chương trình đọc từ tệp Dữ liệu.int chứa 2 số nguyên bất kì . Tính và ghi kết quả vào tệp Kết quả.out 2 dòng , dòng đầu ghi giá trị tổng 2 số , dòng thứ 2 ghi giá trị trung bình của 2 số đó
#include <bits/stdc++.h>
using namespace std;
long long a,b;
double tb;
int main()
{
freopen("dulieu.inp","r",stdin);
freopen("ketqua.out","w",stdout);
cin>>a>>b;
cout<<a<<" "<<b;
cout<<fixed<<setprecision(2)<<(a*1.0+b*1.0)/(2*1.0);
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 SONGUYEN.INP, chứa một dãy số nguyên bất kì:
Viết chương trình pascal: Tính tổng các số chẵn trong dãy số nguyên đó. kết quả ghi vào tệp TONG.OUT.
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.
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.
Đọc dữ liệu từ tệp có tên DL.Dat chứa các số nguyên. đếm trong tệp có bao nhiêu số là số chính phương đồng thời là số hoàn hảo. Kết quả ghi vào tệp KQ.Dat