countoddeven.js
/*Count odd even numbers
Count number of odd and even number in given list.
Input
First line contains length of the list. Each line contains integer specifying each element in list.
Output
2 integers in each line specifying count of odd and even numbers respectively.
Example
Input:
5
12
14
15
13
18
Output:
2
3
*/
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();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
const noOfInputs = parseInt(readLine()); // 5
let oddCount = 0;
let evenCount = 0;
let i = 0; // intialisation of while loop
while (i < noOfInputs) {
const numbers = parseInt(readLine());
if (numbers % 2 != 0) {
oddCount++
}
else
{
evenCount++
}
i++; // increment of while loop
}
console.log(oddCount);
console.log(evenCount);
//////////////////////////////////////////////////////////////////////////////////////////////
TERMINAL:

Comments
Post a Comment