The population of town A is less than the population of town B. However, the population of town A is growing faster than the population of town B.
Write a program that prompts the user to enter:
The program outputs:
(A sample input is: Population of town A = 5,000, growth rate of town A = 4%, population of town B = 8,000, and growth rate of town B = 2%.)
Create a Python script which will accept a positive integer (n) and any character then it will display the input character n times.
Sample Output:
Positive Integer (n) : 7
Input any Character : A
A A A A A A A
I need the code to have an output stated above.
product of array items
given an array integers, write a JS program to get the product of the given integers in the array
sample input1
[1,2,3]
sample output1
1*2*3 = 6
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
let integers = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
}
Squares of array items
given an array myArray write a JS program to get the squares of each item in the given array
input1
[[1,2],[3,4][5,6]]
output1
[ [1,4],[9,6], [25, 36]]
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
let myArray = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
}
find the first value
given an array myArray of positive integers, write a JS program to find the first smallest integer divisible 2 and 3 Log the number or Undefined.in case no integer is found divisible by 2 and 3
input1
[51,18,15,12]
output1
[12]
input2
[41,29,17,19,31]
output2
undefined
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
let myArray = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
}
Replacing array Item
Given an array myArray, targetItem and a replace item write a JS program to replace the targetItem with the given replacement in myArray consists of more than one targetItem replace the first occurence.
sample input1
[1,2,3,'four'5,6]
'four'
4
sample output1
[1,2,3,4,5,6]
function readLine() {
return inputString[currentLine++];
}
function main() {
let myArray = JSON.parse(readLine().replace(/'/g, '"'));
let targetItem = JSON.parse(readLine().replace(/'/g, '"'));
let replaceItem = JSON.parse(readLine().replace(/'/g, '"'));
/* Please do not modify anything above this line */
/* Write your code here and log the output */
}
concatenate and remove Duplicates
Given two arrays arr1 and arr2 of positive integers write a JS program to concatenate two rows and remove duplicates from the concatenated array. Log the array with unique items in ascending order
input1
[1,4,7,3,7,3,3]
[2,4,5,5,3,2,1]
output1
[1,2,3,4,5,7]
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
let arr1 = JSON.parse(readLine());
let arr2 = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here and log the output */
}
The function accepts two positive integers ‘r’ and ‘unit’ and a positive integer array ‘arr’ of size ‘n’ as its argument ‘r’ represents the number of rats present in an area, ‘unit’ is the amount of food each rat consumes and each ith element of array ‘arr’ represents the amount of food present in ‘i+1’ house number, where 0 <= i
Common arrays in three arrays
given three arrays arr1,arr2,arr3 write a JS program to find the common items in the among three arrays.
sample input1
[1,2,3,'cat']
[1,'cat',4]
[1,'cat,64]
output1
[1,'cat']
sample input2
['cat','rat','dog']
['lion','fox']
['kiwi','eagle']
output2
[]
function readLine() {
return inputString[currentLine++];
}
function main() {
let arr1 = JSON.parse(readLine().replace(/'/g, '"'));
let arr2 = JSON.parse(readLine().replace(/'/g, '"'));
let arr3 = JSON.parse(readLine().replace(/'/g, '"'));
/* Please do not modify anything above this line */
/* Write your code here */
}
Cumulative Sum
given an array integers, write a JS program to get the cumulative sum of the items in the array
sample input1
[1, 10, 100, 1000]
sample output1
[1, 11, 111, 1111]
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
function main() {
let integers = JSON.parse(readLine());
/* Please do not modify anything above this line */
/* Write your code here */
}