JavaScript Sayının Kuvvetini Hesaplayan Program

S

Shiva

Veteran
Joined
Jul 31, 2019
Messages
4,067
Reaction score
13,319
Location
Berlin
JavaScriptte Math kütüphanesi ile sayının üssünü hesaplamak mümkün fakat bu JavaScript örneğinde kütüphane kullanmadan sayının kuvvetini hesaplayan programı yapacağız.

Bir sayının kuvveti tabanın üstte belirtilen sayı kadar çarpılması ile hesaplanır. Aşağıdaki javascript kodları sayının kuvvetini hesaplayan programa aittir.

JavaScript Kodu:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Örnekleri</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style="background: #f1f2f6;">
<div class="container">
<h2>Sayının Kuvvetini Hesaplayan Program</h2>
<form>
<div class="form-group">
<label>Taban:</label>
<input type="text" class="form-control" id="sayi1" >
<small class="form-text text-muted">Taban değerini girin.</small>
</div>
<div class="form-group">
<label>Kuvvet:</label>
<input type="text" class="form-control" id="sayi2" >
<small class="form-text text-muted">Sayının kuvvetini girin.</small>
</div>
<div class="form-group">
<label>İşlem: <span id="kok"></span><sup id="ust"></sup></label>
<input type="text" class="form-control" id="sonuc" disabled>
</div>
<button id="hesapla" type="button" class="btn btn-primary">Hesapla</button>
</form>
</div>

<script>
var sayi1=document.querySelector("#sayi1");
var sayi2=document.querySelector("#sayi2");
var sonuc=document.querySelector("#sonuc");
var hesapla=document.querySelector("#hesapla");

/*üs hesaplama işlemi*/
hesapla.onclick=function(){
var taban = Number(sayi1.value);
var kuvvet = Number(sayi2.value);
var islem = 1;

while (kuvvet != 0)
{
islem *= taban;
--kuvvet;
}
sonuc.value=islem;
}

/*işlem kısmındaki üslü görünüm*/
sayi1.onkeyup=function(){
var kok=document.querySelector("#kok");
kok.innerText=this.value;

}
sayi2.onkeyup=function(){
var ust=document.querySelector("#ust");
ust.innerText=this.value;
}

</script>

</body>
</html>


Ekran Çıktısı:

say%C4%B1n%C4%B1n-kuvvetini-hesaplayan-javascript-program%C4%B1-300x171.png
 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom