
How do I write a program in Pascal to compute the sum 1+2+3+4+…+N for any positive integer N, using a loop to accumulate the sum as S1?
1 Expert Answer

Patrick B. answered 06/25/19
Math and computer tutor/teacher
Program FirstNIntegers (input,output);
var N : integer;
var iLoop : integer;
var iSum : integer;
var iSumSqr : integer;
Begin
N:=-1;
while (N<=0) do
begin
write(' Please Input the POSTIIVE value for N :>');
readln(N);
end;
iSum:=0;
iSumSqr:=0;
for iLoop:= 1 to N do
begin
iSum := iSum + iLoop;
iSumSqr := iSumSqr + iLoop*iLoop;
end;
writeln(' N = ',N);
writeln(' The sum of 1+2+3+...+N = ',iSum);
writeln(' The sum of 1+4+9+...+N^2 = ',iSumSqr);
End.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
Please let me tutor you in Pascal.06/25/19