URGENT!!!!!!!!!!!! VA ROG
Răspunsuri la întrebare
Răspuns:
Rapunsurile sunt in Javascript. Comentariile cu // 1 si asa mai departe reprezinta punctele problemelor.
Explicație:
// Calculeaza suma a doua numere de tip Integer
const sum = (a, b) => parseInt(a) + parseInt(b);
// Calculeaza suma cifrelor de la 1 pana la limita specificata. Ex: 1+2 ... +a
const sumTo = (limit) => {
let result = 0;
if (limit > 0) {
for (let number = 1; number < limit; number++) {
result += number;
}
} else {
console.log("Use numbers with value higher than 0.");
}
return result;
};
// Calculeaza suma cifrelor dintr-un numar
const sumOfDigits = (input) => {
let number = parseInt(input);
let sum = 0;
while (number) {
sum += number % 10;
number = Math.floor(number / 10);
}
return sum;
};
// 1
const func1 = (a, b, c, d) => sum(a, b) / sum(c, d);
// 2
const func2 = (a, b) => func1(sumTo(a), sumTo(b));
// 3 a
const func3a = (input) => {
let number = parseInt(input);
if (number >= 10 && number <= 99) {
const lastDigit = number % 10;
while (number) {
if (number % 10 !== lastDigit) return false;
number = Math.floor(number / 10);
}
return 1;
} else {
return 0;
}
};
// 3 b
const func3b = () => {
for (let number = 10; number < 100; number++) {
if (func3a(number) === 1) {
console.log(number);
}
}
};
// 4 a
const func4a = (x, k = 1) => {
if (x == 0 || x == 1) {
return 1;
} else {
return x * func4a(x - k);
}
}
// 4 b
const func4b = (n, k) => func4a(n, k);
// 5 a
const func5a = (input) => {
const number = parseInt(input);
if (number >= 100 && number <= 999) {
if (sumOfDigits(number) % 3) {
return 0;
} else {
return 1;
}
}
};
// 5 b
const func5b = () => {
for (let number = 100; number < 1000; number++) {
if (func5a(number) === 1) {
console.log(number);
}
}
};