writeln('Enter the number of terms N:'); readln(N);
writeln('Enter the common ratio q:'); readln(q);
writeln('Enter the initial value a:'); readln(a);
for i := 1 to N do begin sum := sum + a; a := a * q; end;
writeln('Sum of the first ', N, ' terms of the geometric progression:', sum);
end.
Код на Python:
N = int(input("Enter the number of terms N: ")) q = int(input("Enter the common ratio q: ")) a = int(input("Enter the initial value a: ")) sum = 0 for i in range(N): sum += a a *= q print("Sum of the first", N, "terms of the geometric progression:", sum)
program GeometricProgression;
var
N, i, q, a, sum: Integer;
begin
sum := 0;
writeln('Enter the number of terms N:');
readln(N);
writeln('Enter the common ratio q:');
readln(q);
writeln('Enter the initial value a:');
readln(a);
for i := 1 to N do
begin
sum := sum + a;
a := a * q;
end;
writeln('Sum of the first ', N, ' terms of the geometric progression:', sum);
end.
Код на Python:
N = int(input("Enter the number of terms N: "))q = int(input("Enter the common ratio q: "))
a = int(input("Enter the initial value a: "))
sum = 0
for i in range(N):
sum += a
a *= q
print("Sum of the first", N, "terms of the geometric progression:", sum)