Lời giải :
Program hotrotinhoc;
var A,i,n : integer;
begin
write('n='); readln(n);
S:=0;
for i:= 1 to n do
S:=S+(i-(i+1));
write('S=',S);
readln
end.
2)
program hotrotinhoc;
var i,N,tl,tc : integer;
a: array[1..32000] of integer;
begin
write('N='); readln(N);
for i:= 1 to N do
begin
write('a[',i,']='); readln(a[i]);
end;
tl:=0; tc:=0;
for i:= 1 to N do
begin
if a[i] mod 2=0 then tc:=tc+a[i];
if a[i] mod 2=1 then tl:=tl+a[i];
end;
writeln('Tong cac so o vi tri chan la :',tc);
write('Tong cac so o vi tri le la:',tl);
readln
end.
1) uses crt;
var i,n,s:longint;
begin
clrscr;
write('Nhap n: ');readln(n);
for i:=1 to n do
if i mod 2<>0 then s:=s+i else s:=s-i;
write('Tong la: ',s);
readln
end.
2) uses crt;
Var a:array[1..100000] of longint;
i,n,s,s1:longint;
begin
clrscr;
write('Nhap n: '); readln(n);
for i:=1 to n do
begin
write('a[',i,'] = '); readln(a[i]);
end;
for i:=1 to n do
if i mod 2 = 0 then s:=s+a[i];
Writeln('Tong cac so o vi tri chan la: ',s);
for i:=1 to n do
if i mod 2<>0 then s1:=s1+a[i];
write('Tong cac so o vi tri le la: ',s1);
readln
end.
bài 1
uses crt; var i,t,n:longint; begin write('nhap n:');readln(n); t:=0; for i:=1 to n do if i mod 2<>0 then t:=t+i else t:=t-i; write('Tong la: ',t); readln end.bài 2
uses crt; var n,i,c,l:longint; a:array[1..1000]of integer; begin write('nhap n:');readln(n); c:=0; l:=0; for i:=1 to n do begin write('nhap vi tri thu ',i,' :');readln(a[i]); if i mod 2=0 then c:=c+a[i] else l:=l+a[i]; end; writeln('tong cac so o vi tri chan la :',c); writeln('tong cac so o vi tri le la:', l); readln end;