

Tìm các số là trung bình cộng của hai số khác trong mảng.
ví dụ:
nhập:
8 43 29 89 38 96 27 37 47
kết quả:
38 37
ghi chú: (29+47)/2=38
(27+47)/2=37
ví dụ:
nhập:
8 43 29 89 38 96 27 37 47
kết quả:
38 37
ghi chú: (29+47)/2=38
(27+47)/2=37
chỗ ví dụ không hiểu lắm, bạn có thể giải thích rõ hơn không?Tìm các số là trung bình cộng của hai số khác trong mảng.
ví dụ:
nhập:
8 43 29 89 38 96 27 37 47
kết quả:
38 37
ghi chú: (29+47)/2=38
(27+47)/2=37
Nhập:chỗ ví dụ không hiểu lắm, bạn có thể giải thích rõ hơn không?
Nhập:
n=8
43 29 89 38 96 27 37 47
Kết quả:
38 37
ghi chú:
(29+47)/2=38 (38 là trung bình cộng của 2 số 29 và 47)
(27+47)/2=37 ((37 là trung bình cộng của 2 số 27 và 47)
Anh không hiểu bài nàyprogram QUATANG;
uses crt;
var n,i,j,k,dem:word;
tb,t:real;
a:array[1..500] of longint;
f:text;
str:string;
begin
clrscr;
writeln;
assign(f,'D:\QUATANG.INP');
reset(f);
readln(f,n);
for i:=1 to n do read(f,a);
close(f);
writeln('du lieu nhap vao tep QUATANG.INP la:');
reset(f);
while not eof(f) do
begin
readln(f,str);
writeln(str);
end;
close(f);
assign(f,'D:\QUATANG.OUT');
rewrite(f);
dem:=0; t:=0;
i:=1;
while i<=n do
begin
tb:=a;
j:=1;
if i=j then inc(j);
while a[j]<>a do
begin
k:=j+1;
while a[k]<>a[j] do
begin
if (tb=((a[j]+a[k])/2)) and (a<>t) then
begin
t:=tb;
dem:=dem+1;
end;
inc(k);
if k>n then break;
end;
inc(j);
if j=n then break;
end;
inc(i);
end;
write(f,dem);
close(f);
writeln;
writeln('du lieu ghi ra tep QUATANG.OUT la:');
reset(f);
while not eof(f) do
begin
readln(f,str);
writeln(str);
end;
close(f);
readln;
end.
chúc bạn học tốt![]()
chương trình không ổn bạn ơiprogram QUATANG;
uses crt;
var n,i,j,k,dem:word;
tb,t:real;
a:array[1..500] of longint;
f:text;
str:string;
begin
clrscr;
writeln;
assign(f,'D:\QUATANG.INP');
reset(f);
readln(f,n);
for i:=1 to n do read(f,a);
close(f);
writeln('du lieu nhap vao tep QUATANG.INP la:');
reset(f);
while not eof(f) do
begin
readln(f,str);
writeln(str);
end;
close(f);
assign(f,'D:\QUATANG.OUT');
rewrite(f);
dem:=0; t:=0;
i:=1;
while i<=n do
begin
tb:=a;
j:=1;
if i=j then inc(j);
while a[j]<>a do
begin
k:=j+1;
while a[k]<>a[j] do
begin
if (tb=((a[j]+a[k])/2)) and (a<>t) then
begin
t:=tb;
dem:=dem+1;
end;
inc(k);
if k>n then break;
end;
inc(j);
if j=n then break;
end;
inc(i);
end;
write(f,dem);
close(f);
writeln;
writeln('du lieu ghi ra tep QUATANG.OUT la:');
reset(f);
while not eof(f) do
begin
readln(f,str);
writeln(str);
end;
close(f);
readln;
end.
chúc bạn học tốt![]()
không ổn chỗ nào vậy bạn, mình làm ra kết quả thì đúng rồi đóchương trình không ổn bạn ơi
Anh không hiểu bài này
Em có thể đưa ra thuật toán chứ không nên code
Tìm các số là trung bình cộng của hai số khác trong mảng.
ví dụ:
nhập:
8 43 29 89 38 96 27 37 47
kết quả:
38 37
ghi chú: (29+47)/2=38
(27+47)/2=37