Problem 17. geometricprogression.js

 /*Question

Geometric Progression
Given first 3 numbers of a geometric progression, predict the next number.

You can refer to the following link for information about geometric preogression

https://en.wikipedia.org/wiki/Geometric_progression

Input
3 integers should be taken as a input

Output
single integer.

Note: Convert the output to integer

Example
Input:

2

4

8

Output:

16
*/

let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');

function readLine() {
idx++;
return data[idx - 1].trim();
}
//..............................................................................................................................

let n1 = parseInt(readLine()); // 2

let n2 = parseInt(readLine()); // 4

let n3 = parseInt(readLine()); // 8

console.log(parseInt(n3 * (n2 / n1))); // n2/n1 will give the common ratio between the
numbers
// 4/2 = 2 , therefore 2 is the common ration between the numbers , now 8*2 = 16

Terminal:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node geometricprogression.js <input.txt 16 Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$

Comments

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js

Problem 16. chocolatebills.js