2 câu trả lời
cách 1:
program bai_giai;
uses crt;
var s,i,n:longint;
begin
clrscr;
write('nhap n:');readln(n);
s:=0;
for i:=1 to n do s:=s+i*i;
write('s=',s);
readln
end.
cách 2:
program bai_giai;
uses crt;
var s,i,n:longint;
begin
clrscr;
write('nhap n:');readln(n);
s:=0;
for i:=1 to n do s:=s+sqr(i);
write('s=',s);
readln
end.
Câu 1:
uses crt;
var s,i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=0 to n do
if i mod 2=0 then s:=s+i;
writeln('S=',s);
readln;
end.
Câu 2:
uses crt;
var s:real;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
for i:=1 to n do
s:=s+1/i;
writeln('S=',s:4:2);
readln;
end.
Câu 3:
uses crt;
var a:array[1..100]of integer;
n,i,tb:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tb:=0;
for i:=1 to n do
tb:=tb+a[i];
writeln('Trung binh cong=',tb/n:4:2);
readln;
end.