You are given an array of integers of size N. Check if its elements listed in the same order form a geometric progression
You are given an array of integers of size N. Check if its elements listed in the same order form a geometric progression. If they form, then output the denominator of the progression, if not, then output 0.
program zz1;
const n = 5; // set the number of elements in the array
var i, k, v: integer; // set variables of integer type
m: array [1..n] of integer;
begin
for i: = 1 to n do // get n numbers from the keyboard and write them into an array
read (m [i]);
k: = m [2] div m [1]; // find the denominator
for i: = 1 to n-1 do
if m [i] * k = m [i + 1] then v: = v + 1; // check if each subsequent number, starting from the second,
// obtained from the previous one by multiplying it by the denominator, then we consider it
if v = n -1 then write (‘array elements form a geometric progression, denominator =’, k) else write (0);
end.