VB For Döngüsü Örnek III-IV

by Pınar Demir on 24 Mart 2011

ÖRNEK 3:

Göster düğmesine tıklandığında girilen sayının faktöriyelini alarak sonucu gösterir.

Public Class Form1

Dim a As Integer

Dim f As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

a = Val(TextBox1.Text)

f = 1

For i = 1 To a

f = f * i

Next

Label3.Text = f

End Sub

End Class

Ya da

Public Class Form1

Dim a As Integer

Dim f As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

f = 1

For i = TextBox1.Text To 1 Step -1

f = f * i

Next

Label3.Text = f

End Sub

End Class

ÖRNEK 4:

Kuvveti Hesapla düğmesine tıklandığında, girilen sayının, yine girilen kuvvet değerine göre kuvvetini alıp, sonuç kutucuğunda gösterir.

 

 

 

 

 

 

Public Class Form1

Private Sub hesapla_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hesapla.Click

Dim carpim, s, i As Integer

carpim = 1 ‘ sıfır yutan eleman olduğundan, carpim’in ilk değerini

1 belirledik.

s = sayi.Text

For i = kuvvet.Text To 1 Step -1

carpim = carpim * s

sonuc.Text = carpim

Next

End Sub

End Class

 

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

*

Şu HTML etiketlerini ve özelliklerini kullanabilirsiniz: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>