viet chuong trinh tinh trung binh cong cua day so tu M den N bang cau lenh lap for do va while do 22/07/2021 Bởi Ruby viet chuong trinh tinh trung binh cong cua day so tu M den N bang cau lenh lap for do va while do
uses crt; var m,n,i,t,dem:integer; tbc:real; begin clrscr; write(‘nhap m(m<n)=’); readln(m); write(‘nhap n=’); readln(n); if m>n then exit else begin dem:=0; t:=0; for i:=m to n do begin inc(dem); t:=t+i; end; tbc:=t/dem; writeln(‘Trung binh cong cac so tu ‘,m,’ toi ‘,n,’ la: ‘,tbc:4:2); end else writeln(‘vui long nhap lai’); readln; end. Bình luận
program trungbinh; uses crt; var m,n,i,d:integer; t:longint; begin clrscr; repeat write(‘Nhap m: ‘); readln(m); write(‘Nhap n: ‘); readln(n); if m>=n then writeln(‘m phai be hon n. Nhap lai!’); until (m<n); d:=0; t:=0; i:=m; while i<=n do begin d:=d+1; t:=t+i; i:=i+1; end; write(‘Trung binh cong cac so tu ‘,m,’ den ‘,n,’ la: ‘,t/d:2:2); readln; end. Bình luận
uses crt;
var m,n,i,t,dem:integer;
tbc:real;
begin
clrscr;
write(‘nhap m(m<n)=’); readln(m);
write(‘nhap n=’); readln(n);
if m>n then exit
else
begin
dem:=0;
t:=0;
for i:=m to n do
begin
inc(dem);
t:=t+i;
end;
tbc:=t/dem;
writeln(‘Trung binh cong cac so tu ‘,m,’ toi ‘,n,’ la: ‘,tbc:4:2);
end
else writeln(‘vui long nhap lai’);
readln;
end.
program trungbinh;
uses crt;
var m,n,i,d:integer;
t:longint;
begin
clrscr;
repeat
write(‘Nhap m: ‘); readln(m);
write(‘Nhap n: ‘); readln(n);
if m>=n then writeln(‘m phai be hon n. Nhap lai!’);
until (m<n);
d:=0; t:=0;
i:=m;
while i<=n do
begin
d:=d+1;
t:=t+i;
i:=i+1;
end;
write(‘Trung binh cong cac so tu ‘,m,’ den ‘,n,’ la: ‘,t/d:2:2);
readln;
end.