Sunday, December 9, 2012

Fabonacci series,factorial of a number or prime number in visual basic.


Dim i, f, n As Integer
Dim a, b, c As Integer
Private Sub Cmdtable_Click()
n = Val(Text1.Text)
Me.Cls
For i = 1 To 10 Step 1
Me.Printi * n
Next i
End Sub

Private Sub CmdFabonaccii_Click()
Me.Cls
a = 0
b = 1
Me.Print a
Me.Print b
For j = 3 To 10 Step 1
c = a + b
a = b
b = c
Me.Print c
Next j
End Sub

Private Sub CmdFactorial_Click()
fact = 1
n = Val(Text1.Text)
i = 1
Do While (i<= n)
fact = fact * i
i = i + 1
Loop
MsgBox "the factorial is: " & fact
End Sub
Private Sub CmdPrime_click()
n = Val(Text1.Text)
Me.Cls
If n Mod 2 = 0 Then
Me.Print n & " is not prime"
Else
Me.Print n & " is prime"
End If
End Sub


Private Sub CmdExit_Click()
End
End Sub

 Output


 
Note:- Please set some property of your control like caption or id corresponding to your control