Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
const fi='dulieu.dat';
fo='ketqua.dat';
var f1,f2:text;
n,i,s:integer;
a:array[1..100]of integer;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
n:=0;
while not eof(f1) do
begin
n:=n+1;
read(f1,a[n]);
end;
s:=0;
for i:=1 to n do
s:=s+a[i];
writeln(f2,s);
close(f1);
close(f2);
end.
Câu 3:
Program hotrotinhoc_hoc24;
const fi='dulieu.dat';
fo='dtb.dat';
var a,b,c,d: integer;
procedure ip;
begin
assign(f,fi);
reset(f);
readln(f,a,b);
read(f,c,d);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
write(f,(a+b+c+d)/4:1:2);
close(f);
end;
begin
ip;
out;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[10],b[10],i,j;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
for (i=1; i<=10; i++) cin>>a[i];
for (j=1; j<=10; j++) cin>>b[j];
for (i=1; i<=10; i++)
cout<<a[i]+b[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
freopen("dulieu.txt","r",stdout);
freopen("ketqua.txt","w",stdout);
cin>>a>>b;
cout<<a+b;
return 0;
}
uses crt;
const fi='dulieu.txt';
var f1:text;
a:array[1..100]of real;
t:real;
i,n:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,n);
for i:=1 to n do readln(f1,a[i]);
t:=0;
for i:=1 to n do t:=t+a[i];
writeln(t);
close(f1);
readln;
end.
Bài 1:
uses crt;
var a:array[1..100]of integer;
n,i,j,tam:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('Day so sau khi sap xep la: ');
for i:=1 to n do
write(a[i]:4);
readln;
end.
Bài 2:
const fi='chucai.inp';
fo='chucai.equ';
var f1,f2:text;
s:array[1..255]of string;
dem,dem1,i,j:integer;
x:shortstring;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
dem:=0;
while not eof(f1) do
begin
inc(dem);
readln(f1,s[dem]);
end;
for i:=1 to dem do
begin
dem1:=0;
x:=s[i];
for j:=1 to length(x) do
if (x[j] in ['a'..'z']) or (x[j]in ['A'..'Z']) then inc(dem1);
writeln(f2,dem1);
end;
close(f1);
close(f2);
end.
Bài 1:
const fi='mangmin.inp';
fo='mangmin.out';
var f1,f2:text;
a,vt:array[1..100]of integer;
n,i,dem: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]);
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
dem:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem);
vt[dem]:=i;
end;
writeln(f2,'Gia tri nho nhat la: ',min);
writeln(f2,'Vi tri cua gia tri nho nhat la: ');
for i:=1 to dem do
write(f2,vt[i]:4);
close(f1);
close(f2);
end.
Bài 2:
const fi='mangchan.inp';
fo='mangchan.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
if a[i] mod 2=0 then t:=t+a[i];
writeln(f2,t);
close(f1);
close(f2);
end.
Bài 3:
const fi='tachxau.inp';
fo='tachxau.out';
var f1,f2:text;
s,s1,s2,s3,s4:string;
i,d:integer;
j,k,l:char;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,s);
d:=length(s);
s1:='';
for i:=1 to d do
if s[i] in ['0'..'9'] then s1:=s1+s[i];
writeln(f2,'Xau S1 la: ',s1);
s2:='';
for i:=1 to d do
if s[i] in ['a'..'z'] then s2:=s2+s[i];
writeln(f2,'Xau S2 la: ',s2);
s3:='';
for i:=1 to d do
if s[i] in ['A'..'Z'] then s3:=s3+s[i];
writeln(f2,'Xau S3 la: ',s3);
close(f1);
close(f2);
end.
Bài 4:
const fi='demtu.inp';
fo='demtu.out';
var s:string;
i,d,dem:integer;
kt:boolean;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,s);
d:=length(s);
i:=0;
while i<=d do
begin
inc(i);
if ((i=1) and (s[i]=' ')) then
repeat
kt:=false;
if (s[i]=' ') then
begin
delete(s,i,1);
d:=length(s);
end
else kt:=true;
until (kt=true) or (i+1>d)
else repeat
kt:=false;
if (s[i]=' ') and (s[i+1]=' ') then
begin
delete(s,i,1);
d:=length(s);
end
else kt:=true;
until (kt=true) or (i+1>d);
d:=length(s);
end;
while s[d]=' ' do
begin
delete(s,d,1);
d:=length(s);
end;
dem:=0;
for i:=1 to d do
if s[i]=' ' then dem:=dem+1;
writeln(f2,dem+1);
close(f1);
close(f2);
end.
*Viết chương trình ghi hai số 5 và 15 vào tệp so.txt:
const f='so.txt';
var f1:text;
begin
assign(f1,f); rewrite(f1);
writeln(f1,'5 15');
close(f1);
end.
*Viết chương trình tính tổng, hiệu, tích, thương của x,y và in kết quả ra màn hình:
uses crt;
const fi='so.txt';
var x,y:integer;
f1:text;
begin
clrscr;
assign(f1,fi); reset(f1);
readln(f1,x,y);
writeln('Tong la: ',x+y);
writeln('Hieu la: ',x-y);
writeln('Tich la: ',x*y);
writeln('Thuong la: ',x/y:4:2);
close(f1);
readln;
end.
Program HOC24;
const fi='DULIEU.DAT';
fo='KETQUA.DAT';
var a,x,n: integer;
s: longint;
function luythua(a,b: integer): longint;
var j,t: longint;
begin
t:=1;
for j:=1 to b do t:=t*a;
luythua:=t;
end;
procedure ip;
begin
assign(f,fi);
reset(f);
read(f,a,x,n);
close(f);
end;
procedure out;
begin
assign(f,fo);
rewrite(f);
s:=1;
for i:=1 to n do
s:=s+luythua(x,i)*(a+i);
write(f,s);
close(f);
end;
begin
ip;
out;
end.