Problem 39. arithmetics.js ( coding test)
/*Question
Arithmetics
Given two integers a and b, print the following three lines as output.
The first line contains the sum of the two numbers.
The second line contains the difference of the two numbers (first - second).
The third line contains the product of the two numbers.
Input
The first line contains the first integer, a. The second line contains the second integer, b.
Output
Print the three lines as explained above.
Example
Input:
3
2
Output:
5
1
6
Explanation:
3+2 => 5
3-2 => 1
3*2 => 6
*/
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 a = parseInt(readLine()); //3
let b = parseInt(readLine()); // 2
console.log(a + b);
console.log(a - b);
console.log(a * b);
TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node arithmetics.js <input.txt
5
1
6
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$
Comments
Post a Comment