Problem 6. simpleinterest.js
/*Simple interest
Simple interest formula is given by: Simple Interest = (P x T x R)/100 Where,
P is the principle amount T is the time and R is the rate.
Compute simple interest for given P, T and R.
Input
Three lines containing integer each.
Output
One line containing integer.
Example
Input:
1000
10
5
Output: 500
*/
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 principleAmount = parseInt(readLine()); // 1000
let time = parseInt(readLine()); // 10
let rate = parseInt(readLine()); // 5
let simpleInterest = (principleAmount * time * rate) / 100;
console.log(simpleInterest); // 500
Terminal:-
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node simpleinterest.js <input.txt
500
Comments
Post a Comment