rdsedmundo

Calcular Equação do 2º Grau

Jul 5th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // by kyl3 :D
  2. (function(){var a,b,c,d,e,f,g,h,i;a=prompt("Digite o valor do coeficiente a","");b=prompt("Digite o valor do coeficiente b","");c=prompt("Digite o valor do termo independente c","");d=a/a;e=b/b;f=c/c;if(d!==1||e!==1||f!==1){alert("Valores inválidos\n"+d+"\n"+e+"\n"+f);return 0}g=b*b-4*a*c;console.log("DELTA: "+g);if(g<0){alert("DELTA < 0, não existe raiz real");return 0}else if(g==0){console.log("DELTA = 0; existem duas raízes reais iguais")}else{console.log("DELTA > 0; existem duas raízes reais diferentes")}h=(-b+Math.sqrt(g))/(2*a);i=(-b-Math.sqrt(g))/(2*a);alert("RESPOSTA 1: "+h+"\nRESPOSTA 2: "+i)})()
Advertisement
Add Comment
Please, Sign In to add comment