Tìm tổng các số bất kỳ từ dãy 1,2,2,3,3,3,4,4,4,4...
program code;
var di:word;
m,n,i,res:longint;
begin
writeln('Nhap M: '); readln(m);
writeln('Nhap N: '); readln(n);
di:=0;
i:=0;
res:=0;
while i<m do
begin
di:=di+1;
i:=i+di;
end;
res:=(i-m+1)*di;
while i<=n do
begin
di:=di+1;
i:=i+di;
res:=res+di*di;
end;
res:=res-di*(i-n);
writeln('Ket qua: ',res);
readln;
end.
0 nhận xét:
Đăng nhận xét
Click to see the code!
To insert emoticon you must added at least one space before the code.