program SumOfFirstN;varn, a1, a2, an, sum: integer;beginwriteln('Enter the value of n:');readln(n);
writeln('Enter the value of the second element:');readln(a2);
writeln('Enter the value of the fourth element:');readln(a1);a1 := a2 + 2 * (a2 - a1);
sum := n * (a1 + a2) div 2;
writeln('The sum of the first ', n, ' terms of the arithmetic progression is ', sum);end.
program SumOfFirstN;
var
n, a1, a2, an, sum: integer;
begin
writeln('Enter the value of n:');
readln(n);
writeln('Enter the value of the second element:');
readln(a2);
writeln('Enter the value of the fourth element:');
readln(a1);
a1 := a2 + 2 * (a2 - a1);
sum := n * (a1 + a2) div 2;
writeln('The sum of the first ', n, ' terms of the arithmetic progression is ', sum);
end.