Functia Ackerman

Schema Logica Slide 10

by MariusNastasa

HTML

<h2>Ackermann</h2>
<input type="number" placeholder="Introduceti x" id="val1">
<input type="number" placeholder="introduceti y" id="val2">
<button onclick="ack()">Ackermann</button>
<p id="result"></p>
<hr>
<hr>
<h2>Produsul a n numere pare<h2>
<input id="val">
<button onclick="run();">Calculeaza</button>
<p id="results">Rezultat</p>

CSS

body {
  background-color: moccasin;
}

h2 {
  color: #ff8000;
  font-variant: small-caps;
}

placeholder {
  font-variant: small-caps;
}

button {
  border-radius: 12px;
  border-style: solid
}

button:hover span:after {
  opacity: 1;
  right: 0;
}

JavaScript

function ackr() {
  var x = document.getElementById("val1").value;
  var y = document.getElementById("val2").value;
  if (x == 0) {
    return y + 1;
  }
  if (y == 0) {
    return ack(x - 1, 1);
  } else {
    return ack(x - 1, ack(x, y - 1));
    }
    console.log(ack(3,5));
 //Maximum call stack size exceeded
}
function ack(x,y){

}

function prod(N) {
  var total = 1;
    for(var i = 1; i <= N; i++){
    if(i%2==0)
      total *= i;
    }
    return total;   
}

function run(){
  val = document.getElementById("val").value;
  document.getElementById("results").innerHTML="Produsul numerelor pare pana la "+ val+ " este "+prod(val)
  }