Pascal:
Câu 19;
Program ViDu;
Uses crt;
n,i,s1,s2,t:real;
kq:string;
BEGIN
Readln(n);
For i:= 1 to n do
begin
t:=sqr(i);
s1:=s1+t;
end;
s2:=(n*(n+1)*(2*n+1))/6
if s1 = s2 then kq := 'Dung' else kq := 'Sai';
Writeln('Bieu thuc da cho voi n= ',n:1:0,' la ', kq );
readln;
END.
Câu 20;
Program ViDu;
Uses crt;
n,i,s1,s2,t:real;
kq:string;
BEGIN
clrscr;
readln(n);
for i: = 1 to n do begin
t := i *i*i;
s1:=s1+t;
end;
s:=0;
for i:= 1 to n do begin
s2:=s2+i;
end;
s2:=sqr(s2);
if s1 = s2 then kq:='dung' else kq:='sai';
Writeln('Bieu thuc da cho voi n= ', n:1:0, 'la ', kq);
readln;
END.
Pỵthon:
Câu 19
n=int(input())
i = 1
s1 = 0
t = 0
while (i <= n):
t = i**2
s1 = s1 +t
i += 1
s2 = ((n**2)*(n+1)*(2*n+1))/6
if s1 == s2:
print('Bieu thuc da cho dung voi n= ' + str(n))
else:
print('Bieu thuc da cho sai voi n = ' + str(n))
Câu 20
n=int(input())
i = 1
s1 = 0
t = 0
while (i <= n):
t = i**3
s1 = s1 +t
i += 1
i = 1
s2 = 0
while (i <= n):
s2 = s2 + i
i+=1
s2 = s2**2
if s1 == s2:
print('Bieu thuc da cho dung voi n= ' + str(n))
else:
print('Bieu thuc da cho sai voi n = ' + str(n))