Mình làm như vầy đây, có sai sót gì thì nói nhé:
Code:
program phantich;
uses crt;
var
n,k,l:longint;
i:byte;
s:string;
begin
clrscr;
repeat
write('-Nhap so n (n>=0): ');
readln(n);
k:=n;
write(n,' = ');
if ((n<4) and (n>0)) then
for i:=1 to n do
if i=n then writeln('1^2')
else write('1^2 + ')
else if n=0 then writeln('0^2')
else while k<>0 do
begin
l:=k;
l:=trunc(sqrt(l));
k:=k-sqr(l);
if k=0 then writeln(l,'^2')
else write(l,'^2 + ');
if k<4 then
for i:=1 to k do
if i=k then begin
writeln('1^2');
k:=0;
end
else write('1^2 + ')
end;
write('-Co muon nhap lai khong (C/K): ');
readln(s);
writeln;
until upcase(s)='K';
writeln('-Nhan Enter de thoat');
readln
end.
Bookmarks