0% found this document useful (0 votes)
47 views4 pages

Laborator 11

Uploaded by

Adrian Floroiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

Laborator 11

Uploaded by

Adrian Floroiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.Cititi trei numere si afisati suma si produsul lor.

<html>
<head>
<title>Exercitiul 1</title>
</head>
<body>
<script type = "text/javascript">
a = parseInt(prompt("Introduceti numarul a",0));
b = parseInt(prompt("Introduceti numarul b",0));
c = parseInt(prompt("Introduceti numarul c",0));
s = a + b + c;
p = a * b * c;
alert("suma = " + s + "\n" + "produsul = " + p);
</script>
</body>
</html>

2.Cititi a, b numere naturale si rezolvati ecuatia ax+b=0.

<html>
<head>
<title>Exercitiul 2</title>
</head>
<body>
<script type = "text/javascript">
a = parseInt(prompt("Introduceti numarul natural a",0));
b = parseInt(prompt("Introduceti numarul natural b",0));
x = -b / a;
alert("Solutia ecuatiei este x = " + x);
</script>
</body>
</html>

3.Cititi a, b, c numere natural nenule si rezolvati ecuatia ax 2+bx+c=0.

<html>
<head>
<title>Exercitiul 3</title>
</head>
<body>
<script type = "text/javascript">
a = parseInt(prompt("Introduceti numarul natural a",0));
b = parseInt(prompt("Introduceti numarul natural b",0));
c = parseInt(prompt("Introduceti numarul natural c",0));
delta = b * b - 4 * a * c;
if(delta < 0)
alert("Ecuatia nu are solutii reale");
else if(delta > 0)
{
x1 = (-b + Math.sqrt(delta)) / (2 * a);
x2 = (-b - Math.sqrt(delta)) / (2 * a);
alert("Ecuatia are solutiile x1 = " + x1 + " x2 = " + x2); }
else
{
x = -b / (2 * a);
alert("Ecuatia are solutia x = " + x); }
</script>
</body>
</html>

4.Cititi n numere naturale si afisati aceste numere in ordine crescatoare, respectiv descrescatoare.

<html>
<head>
<title>Exercitiul 4</title>
<script type = "text/javascript">
n = parseInt(prompt("Introduceti numarul de componente al vectorului",0));
x = new Array();
for(i=1;i<=n;i++)
x[i] = parseInt(prompt("Introduceti a - " + i + " -a componenta",0));
x.sort(function(a, b){return a-b});
alert("Elementele vectorului sortate crescator sunt: " + x.toString().slice(0,
-1));

x.sort(function(a, b){return b-a});


alert("Elementele vectorului sortate descrescator sunt: " +
x.toString().slice(0, -1));
</script>
</head>
<body>
</body>
</html>

5.Cititi numele si prenumele unei presoane si apoi afisati separate numele, respective prenumele pe
randuri diferite.

<html>
<head>
<title>Exercitiul 5</title>
</head>
<body>
<script type = "text/javascript">
var x = new Array();
x[0] = prompt("Introduceti numele persoanei");
x[1] = prompt("Introduceti prenumele persoanei");

for(i in x)
document.write(x[i] + "<br>");
</script>
</body>
</html>
6.Cititi cnp-ul unei persoane si afisati data nasterii, urmata de varsta sa.

<html>
<head>
<title>Exercitiul 6</title>
</head>
<body>
<script type = "text/javascript">
cnp = prompt("Introduceti CNP-ul persoanei", '');
if(cnp.length != 13)
alert("CNP invalid");
else
{
an = cnp[1] + cnp[2];
luna = cnp[3] + cnp[4];
zi = cnp[5] + cnp[6];
document.write("Data nasterii: " + zi + "/" + luna + "/" + an +
"<br>");
if(an > 40)
an = "19" + an;
else
an = "20" + an;

dataCurenta = new Date();


varsta = dataCurenta.getFullYear() - parseInt(an);

document.write("Varsta: " + varsta);


}
</script>
</body>
</html>

7.Cititi n cuvinte si afisati cuvintele de lungime maxima.

<html>
<head>
<title>Exercitiul 7</title>
</head>
<body>
<script type = "text/javascript">
n = parseInt(prompt("Introduceti numarul de componente al vectorului",0));
x = new Array();
for(i=1;i<=n;i++)
x[i] = prompt("Introduceti a - " + i + " -a componenta", "");

maxL = 0;
for(i=1; i<=n; i++)
{
if(x[i].length > maxL)
maxL = x[i].length;
}

for(i=1; i<=n; i++)


{
if(x[i].length == maxL)
document.write(x[i] + " ");
}

</script>
</body>
</html>

8.Cititi un text in care cuvintele sunt separate prin cate un spatiu. Apoi afisati primul si ultimul cuvant.

<html>
<head>
<title>Exercitiul 8</title>
</head>
<body>
<script type = "text/javascript">
var s = prompt("Introduceti textul", "");
var r = s.split(" ");
document.write(r[0] + "<br>");
r.reverse();
document.write(r[0]);
</script>
</body>
</html>

9.Cititi un text in care cuvintele sunt separate prin cate un spatiu. Apoi afisati cuvintele pe randuri diferite.

<html>
<head>
<title>Exercitiul 9</title>
</head>
<body>
<script type = "text/javascript">
var s = prompt("Introduceti textul", "");
var r = s.split(" ");
for(i in r)
document.write(r[i] + "<br>");
</script>
</body>
</html>

You might also like