-2
Prepare a program that reads two matrices A and B of a six-element dimension. The matrix A must accept only the input of even values, while the matrix B must accept only input of odd values. The input of the matrices must be validated by the program. Construct the matrix C that is the result of joining the matrices A and B, so that the matrix C contains 12 elements. Display the elements of matrix C.
console.log('Exercício 06')
var matriz06A = [];
var matriz06B = [];
var matriz06C = [];
function fpares (num){
n = num;
if (n % 2 == 0){
return (n);
}
}
function fimpares (num){
n = num;
if (n % 2 == 1){
return (n);
}
}
function felementosA (){
for (var i = 0; i < 6; i++){
matriz06A.push(fpares(Math.floor(Math.random() * 25 +1)))
matriz06A = matriz06A.filter(function(item){
return item != null
})
}
return matriz06A;
}
function felementosB (){
for (var i = 0; i < 6; i++){
matriz06B.push(fimpares(Math.floor(Math.random() * 25 +1)));
matriz06B = matriz06B.filter(function(item){
return item != null
})
}
return matriz06B;
}
felementosA();
felementosB();
matriz06C = matriz06A.concat(matriz06B);
console.log('Matriz A: '+matriz06A); //este vetor deve possuir 6 elemento
console.log('Matriz B: '+matriz06B);
console.log('Matriz C: '+matriz06C);
console.log(`A matriz C possui ${matriz06C.length} elementos.`)
Hello, take a minute of your time to read about How not to ask questions, will help you improve the body of your questions and get answers easier.
– Leo Letto
Hello Leo, good morning! Thanks for the tip regarding good practices.
– Vitor Amorim