Bài tập tệp Bài 1: Viết chương trình mở tệp dayso.TXT để đọc các số nguyên ra biến n và tính tổng các số nguyên n chia hết cho 3 hoặc 5? Bài 2: Viết chương trình nhập 50 số nguyên bất kì từ bàn phím và ghi các số nguyên lẻ đã nhập vào tập sole.TXT
Cho dãy A gồm N số nguyên (N nhỏ hơn hoặc bằng 200) số nguyên A1,A2,...An. Hãy viết chương trình nhập mảng A vào từ bàn phím và đưa ra màn hình tổng các phần tử chia hết cho 5. Bài 2: Viết chương trình nhập 1 xâu vào từ bàn phím và đưa ra màn hình xâu không chứa dấu cách.
Bài 1:
uses crt;
var a:array[1..200]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if a[i] mod 5=0 then t:=t+a[i];
writeln('Tong cac so chia het cho 5 la: ',t);
readln;
end.
Bài 2:
uses crt;
var st:string;
d,i:integer;
begin
clrscr;
write('Nhap xau:'); readln(st);
d:=length(st);
for i:=1 to d do
if st[i]=#32 then delete(st,i,1);
writeln(st);
readln;
end.
Mng giúp mình các BT cuối kì vs ạ Bài 1: Viết chương trình nhập từ bàn phím 2 số nguyên a,b; Sau đó ghi chúng vào tệp có tên D:\Baitaptin.txt. Bài 2: Viết chương trình nhập từ bàn phím 1 xâu không quá 180 kí tự; Xuất xâu vừa nhập ra màn hình rồi ghi xâu đó vào tệp có tên E:\tepxau.txt. Bài 3: Viết chương trình nhập từ bàn phím 2 số nguyên dương; Tính và ghi tổng của chúng vào tệp có tên ‘teptong.txt’ rồi xuất tổng ra màn hình.
Bài 3:
uses crt;
const fi='teptong.txt'
var a,b:integer;
f1:text;
begin
clrscr;
assign(f1,fi); rewrite(f1);
readln(a,b);
writeln(a+b);
writeln(f1,a+b);
close(f1);
readln;
end.
Viết chương trình cho máy tính đọc từ tệp DAYSO.txt gồm các số nguyên có ít nhất 2 dòng
Tính tổng cấc số có trong tệp DAYSO.txt, ghi kết quả ra màn hình và tệp KETQUA.txt
Tính tổng và trung bình cộng các số chẵn trong tệp dayso.txt, ghi các kết quả vào tệp KETQUA.txt
Uses crt;
var f1,f2:text;
i,n,tong,tongchan,dem:integer;
tb:real;
Begin
clrscr;
Assign(f1,'DAYSO.txt');
Assign(f2,'KETQUA.txt');
reset(f1);dem:=0;tong:=0;tongchan:=0;
While Not EOF(f1) do
Begin
read(f1,i);
inc(tong,i);
If i mod 2 = 0 then
begin
inc(dem);
inc(tongchan,i);
end;
End;
tb:=tongchan/dem;
close(f1);
rewrite(f2);
writeln(f2,tong);
writeln(f2,tongchan);
writeln(f2,tb:0:2);
close(f2);
write(tong);
readln;
End.
Câu 1: Viết chương trình nhập n phần tử mảng 1 chiều là các số nguyên từ bàn phím, ghi mảng vừa nhập vào tệp MANG1CHIEU.TXT. Tìm giá trị nhỏ nhất trong mảng và đưa kết quả ra màn hình
Câu 2: Viết chương trình nhập 1 xâu bất kỳ từ bàn phím, In ra xâu sau khi đã loại bỏ các kí tự là chữ cái và ghi vào tệp CHUSO.TXT
giúp em với ạ . em cảm ơn nhiều...
cau 1:
uses crt;
var a:array[1..100] of integer;
n,i,min: integer;
begin
readln(n);
for i:=1 to n do
readln(a[i]);
min:=a[1];
for i:=2 to n do
if min>a[i] then min=a[i];
writeln(a[i]);
readln;
end.
cau 2:
uses crt;
g:text;
s:string;
const fo='CHUSO.TXT'
begin
assign(g,fo);
rewrite(g);
readln(s);
for i:=1 to length(s) do
if not((s[i] in ['a'..'z'])and(s[i] in ['A'..'Z])) then delete(s,i,1);
writeln(g,s);
end.
Bài tập 3: Hãy cho biết một số nguyên n bất kì
(n đọc vào từ bàn phím) có chia hết cho 2 và 5 hay không?
Yêu cầu:
a) xác định bài toán
b) Mô tả thuật toán
c) Viết chương trình Python
Viết chương trình:
Đọc từ tệp “DULIEU.TXT” 2 số nguyên M và N (M < N)
Tính tổng các số chia hết cho 5 trong phạm vi từ M đến N
Ghi kết quả ra tệp “KETQUA.TXT”.
Var f1, f2: text;
Tong, m, n, i: integer;
Begin
assign(f1, ‘DULIEU.TXT’);
reset(f1);
assign(f2, ‘KETQUA’);
rewrite(f2);
Tong;= 0;
read(f1, m, n);
for i:= m to n do
if i mod 2 = 0 then Tong:= Tong+i;
write(f2, Tong);
close(f1);
close(f2);
End.
Viết chương trình:
Đọc từ tệp “DULIEU.TXT” 2 số nguyên M và N (M < N)
Tính tổng các số chia hết cho 3 trong phạm vi từ M đến N
Ghi kết quả ra tệp “KETQUA.TXT”
Var f1, f2: text;
Tong, m, n, i: integer;
Begin
assign(f1, ‘DULIEU.TXT’);
reset(f1);
assign(f2, ‘KETQUA’);
rewrite(f2);
Tong;= 0;
read(f1, m, n);
for i:= m to n do
if i mod 2 = 0 then Tong:= Tong+i;
write(f2, Tong);
close(f1);
close(f2);
End.
1. Viết chương trình tạo tệp baitap.txt trong đó dòng đầu tiên n là số lượng các số nguyên, dòng thứ 2 là n số nguyên cách nhau 2 kí tự trắng được nhập từ bàn phím (N<=100)
2.Viết chương trình tìm số nguyên lớn nhất trong n số nguyên đã có trong tệp baitap.txt và ghi kết quả vào tệp solonnhat.txt
Mong mọi người giúp mình giải sớm =(((
Câu 2:
uses crt;
var a,b:integer;
{-----------------chuong-trinh-con-------------------}
function ucln(x,y:integer):integer;
var i,uc:integer;
begin
if x<y then
begin
uc:=1;
for i:=1 to x do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end
else begin
uc:=1;
for i:=1 to y do
if (x mod i=0) and (y mod i=0) then
begin
if uc<i then uc:=i;
end;
end;
ucln:=uc;
end;
{--------------------------chuong-trinh-chinh------------------------}
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
writeln(a,'/',b,'=',a div ucln(a,b),'/',b div ucln(a,b));
readln;
end.
Câu 1:
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.
Bài 1: Viết chương trình nhập vào từ bàn phím các số thực a,b,c,d. Tính và đưa ra màn hình giá trị biểu thức: 2cb3 + 5cd4 – 3a? + bcd" - Bài 2: Viết chương trình nhập vào từ bàn phím 2 số nguyên m,n (n>0). Tính và đưa ra màn hình giá trị biểu thức nm-2 ~kíuuuuu~
Bài 2:
#include <bits/stdc++.h>;
using namespace std;
int main();
{
long m,n;
cout<<"Nhap m="; cin>>m;
cout<<"Nhap n="; cin>>n;
cout<<m*n-2;
return 0;
}