Giúp mình với ạ 😥😥
Cho tệp A.in gồm nhiều dòng , mỗi dòng chứa một số nguyên. Hãy đếm và đưa ra các số lẻ. Kết quả ghi vào tệp B.out
Thanks !
cho tệp dulieu.inp gồm các số nguyên mỗi số trên 1 dòng . Đếm các số chẵn. Ghi kết quả ra tệp dulieu.out
const fi='dulieu.inp'
fo='dulieu.out'
var f1,f2:text;
a:array[1..100]of integer;
n,i,dem: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;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln(f2,dem);
close(f1);
close(f2);
end.
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.
Cho tệp BAIKT.INP chứa các số nguyên bất kì. Viết chương trình đếm xem trong tệp có bao nhiêu số lẻ rồi ghi kết quả vào tệp KETQUA.OUT giúp mình với mình đang gấp ạ. Mình cảm ơn nhiềuu
Cho tệp input.txt gồm nhiều dòng , mỗi dòng chứa 1 số nguyên . Hãy ghi ra tệp soạn.txt các số nguyên âm có trong tệp input.txt, mỗi số trên 1 dòng
const fi='input.txt'
fo='soan.txt'
var f1,f2:text;
a:array[1..100]of integer;
i,n: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;
for i:=1 to n do
if a[i]<0 then writeln(f2,a[i]:4);
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
tệp xau.inp gồm các dòng kí tự, mỗi dòng không vượt quá 255 kí tự. viết chương trình đọc dữ liệu từ tệp xau.inp. đếm số kí tự là chữ'a'. ghi kết quả ra tệp xau.out chứa số nguyên duy nhất là số lượng kí tự'a' có trong tệp xau.inp
#include <bits/stdc++.h>
using namespace std;
string st;
int d,i,dem;
int main()
{
freopen("xau.inp","r",stdin);
freopen("xau.out","w",stdout);
cin>>st;
d=st.length();
dem=0;
for (i=0; i<=d-1; i++)
if (st[i]=='a') dem++;
cout<<dem;
return 0;
}
Cho tệp vanban.inp gồm nhiều dòng hãy đọc dữ liệu từ tệp vanban.inp và đếm xem trong tệp có tất cả bao nhiêu dòng rồi ghi kết quả vào tệp vanban.out
const fi='vanban.inp'
fo='vanban.out'
var f1,f2:text;
dem,i:integer;
a:array[1..1000]of string;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
dem:=0;
while not eof(f1) do
begin
inc(dem);
readln(f1,a[dem]);
end;
writeln(f2,dem);
close(f1);
close(f2);
end.
Cho tệp kiemtra.txt chứa 3 số nguyên, mỗi số nằm trên một dòng. Hãy viết chương trình đọc 3 số nguyên từ tệp kiemtra.txt và đưa vào 3 biến a, b, c. Tính và đưa ra màn hình kết quả (a+b)(a+c)(c*b). Giúp e vs mn ơi
uses crt;
const fi='kiemtra.txt'
var f1:text;
a,b,c:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,a);
readln(f1,b);
readln(f1,c);
writeln((a+b)*(a+c)*(c+b));
close(f1);
readln;
end.