viet phuong trinh su dung lenh While -. Do de tinh trung binh cua n so thuc 16/07/2021 Bởi Arya viet phuong trinh su dung lenh While ….. Do de tinh trung binh cua n so thuc
program trung_binh; uses crt; var A:array[1..1000] of real; n,i:integer; t:real; begin clrscr; write(‘Nhap n: ‘); readln(n); i:=0; t:=0; while i<n do begin i:=i+1; write(‘Nhap so thu ‘,i,’: ‘); readln(A[i]); t:=t+A[i]; end; write(‘Tong cua cac so thuc la: ‘,t/n:0:3); readln; end. Bình luận
program trung_binh;
uses crt;
var A:array[1..1000] of real;
n,i:integer;
t:real;
begin
clrscr;
write(‘Nhap n: ‘); readln(n);
i:=0; t:=0;
while i<n do
begin
i:=i+1;
write(‘Nhap so thu ‘,i,’: ‘); readln(A[i]);
t:=t+A[i];
end;
write(‘Tong cua cac so thuc la: ‘,t/n:0:3);
readln;
end.