. Viết chương trình cho phép nhập từ bàn phím 3 số tự nhiên bất kì. Xử lí dữ liệu và ghi vào tệp “Ketqua.txt” tổng, tích và trung bình cộng của 3 số (mỗi kết quả in trên 1 dòng) ,pyhton
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 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 nhập 2 số x,y từ bàn phím, tính tổng, hiệu, tích, thương của 2 số và ghi kết quả vào tệp 'KQ.TXT'
#include <bits/stdc++.h>
using namespace std;
long long x,y;
int main()
{
cin>>x>>y;
freopen("kq.txt","w",stdout);
cout<<x+y<<endl;
cout<<x-y<<endl;
cout<<x*y<<endl;
cout<<fixed<<setprecision(2)<<(x*1.0)/(y*1.0);
return 0;
}
viết chương trình nhập n từ bàn phím(n<=200) và dãy số a1,a2..an từ bàn phím, ghi vào tệp B.TXT mỗi số trên 1 dòng
uses crt;
const fo='b.txt'
var f1:text;
a:array[1..200]of integer;
i,n:integer;
begin
clrscr;
assign(f1,fo); rewrite(f2);
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
write(f1,a[i]:4);
close(f1);
readln;
end.
program cap_so_cong;
uses crt; var a: array[1..100] of integer; i, n, k: integer;
{i la bien dem, k de luu cap so} begin clrscr; write('N= ');
readln(n); for i:=1 to n do begin write('A(',i,')= ');
readln(a[i]);
end;
{Bat dau phan kiem tra} k:=a[2]-a[1]; i:=2; repeat i:= i+1; until (a[i]<>a[i-1]+k) or (i>n);
if i>n then write('Day A la mot cap so cong') else
write('Day A khong phai la mot cap so cong');
readln
end.
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
giúp em với 2 câu thôi ạ :
viết chương trình nhập vào xâu bất kì từ bàn phím , ghi xâu sau khi loại bỏ các dấu cách ra tệp D:\ketqua.txt
viết chương trình nhập vào từ bàn phím 4 số bất A,B,C. tìm và thông báo kết quả ra màn hình giá trị nhỏ nhất MIN của 4 số đó có sử dụng chương trình con
1:
uses crt;
const fi='ketqua.txt'
var f1:text;
st:string;
i,d:integer;
begin
clrscr;
assign(f1,fi); rewrite(f1);
write('Nhap xau:'); readln(st);
d:=length(st);
for i:=1 to d do
if st[i]=#32 then delete(st,i,1);
writeln(f1,st);
close(f1);
end.
2:
uses crt;
var a,b,c,d:integer;
{----------chuong-trinh-con-----------------------}
function min(x,y:integer):integer;
begin
if x<y then min:=x
else min:=y;
end;
{---------------chuong-trinh-chinh--------------------}
begin
clrscr;
write('a='); readln(a);
write('b='); readln(b);
write('c='); readln(c);
write('d='); readln(d);
writeln(min(a,min(b,min(c,d))));
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.
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.
câu 1
Viết - chạy - sửa lỗi ( nếu có ) chương trình in ra trên màn hình dòng chữ " lớp 8A chào bạn ! "
câu 2
Viết chương trình ghi và in ra màn hình kết quả tổng 2 số tự nhận a, b nhập vào từ bàn phím
câu 3
Viết chương trình tính s và chu vi hình chữ nhật biết 2 cạnh nhập từ bàn phím . Lưu tệp với tên HCN . Pas
Câu 3:
program cauba;
int chieudai, chieurong, chuvi, dientich :real;
begin
write('Chieu dai la: '); Readln(chieudai);
write('Chieu rong la: '); Readln(chieurong);
chuvi = (chieudai + chieu rong)*2;
dientich= chieudai*chieurong;
writeln('Chu vi la: ',chuvi);
writeln('Dien tich la: ',dientich);
end.
Caua1:
program caumot;
begin
writeln('lop 8A chao ban!');
end.
Câu 2:
program cauhai;
int a,b,c :real;
begin
write('a='); readln(a);
write('b='); readln(b);
c= a+b;
write('Tong hai so a b la:',c);
end.