to display its square,square root,sum of digits and its reverse
CODE
Form 1
Private Sub Clear_Click(Index As Integer)
Dim i As Integer
For i = 0 To 9
OptionButton(i).Value = False
Next i
Number.Text = ""
Display.Caption = ""
Display.Visible = False
Number.SetFocus
End Sub
Private Sub Exit_Click(Index As Integer)
End
End Sub
Private Sub Form_Load()
Dim i As Integer
Display.Visible = False
For i = 0 To 9
OptionButton(i).Value = False
Next i
End Sub
Private Sub OptionButton_Click(Index As Integer)
Dim Temp As Integer, Sum As Integer, Rev As Integer, Digit As Integer, a As
Integer, b As Integer, c As Integer, i As Integer, Fact As Double, Flag As
Boolean
If IsNumeric(Number.Text) = False Then
MsgBox "Please Enter Number"
Display.Caption = ""
Exit Sub
ElseIf Val(Number.Text) < 0 Then
MsgBox "Please Enter a Positive number"
Exit Sub
ElseIf Len(Number.Text) > 4 Then
MsgBox "Enter a number upto 4 digits"
Exit Sub
End If
Display.Visible = True
Select Case Index
Case 0
If Val(Number.Text) Mod 2 = 0 Then
Display.Caption = Number.Text & "is even"
Else
Display.Caption = Number.Text & "not even"
End If
Case 1
If Val(Number.Text) Mod 2 = 1 Then
Display.Caption = Number.Text & "is odd"
Else
Display.Caption = Number.Text & "is not odd"
End If
Case 2
Temp = Val(Number.Text)
Sum = 0
While Temp > 0
Digit = Temp Mod 10
Sum = Sum + Digit ^ 3
Temp = Int(Temp / 10)
Wend
If Sum = Val(Number.Text) Then
Display.Caption = Number.Text & "is an armstrong number"
Else
Display.Caption = Number.Text & "is not an armstrong number"
End If
Case 3
a = 1: b = 0
While (c < Val(Number.Text))
c = a + b: a = b: b = c
Wend
If c = Val(Number.Text) Then
Display.Caption = Number.Text & "is a Fibonacci number"
Else
Display.Caption = Number.Text & "not a fibonacci number"
End If
Case 4
Fact = 1: i = 1
While Fact < Val(Number.Text)
Fact = Fact * i: i = i + 1
Wend
If Fact = Val(Number.Text) Then
Display.Caption = Number.Text & "is a perfect factorial"
Else
Display.Caption = Number.Text & "is not a perfect factorial"
End If
Case 5
Flag = True
For i = 2 To Sqr(Val(Number.Text))
If Val(Number.Text) Mod i = 0 Then
Flag = False
Exit For
End If
Next i
If Flag Then
Display.Caption = Number.Text & "is a prime number"
Else
Display.Caption = Number.Text & "is not a prime number"
End If
Case 6
Temp = Val(Number.Text)
Sum = 0
While Temp > 0
Digit = Temp Mod 10
Sum = Sum + Digit
Temp = Int(Temp / 10)
Wend
Display.Caption = "Sum of the individual digits of" & Number.Text & "is" &
Str(Sum)
Case 7
Display.Caption = "Square of " & Number.Text & " is " &
Str(Val(Number.Text)) ^ 2
Case 8
Display.Caption = "square root of" & Number.Text & "is " &
Str(Sqr(Val(Number.Text)))
Case 9
Temp = Val(Number.Text)
Rev = 0
While Temp > 0
Digit = Temp Mod 10
Rev = Rev * 10 + Digit
Temp = Int(Temp / 10)
Wend
Display.Caption = "Reverse of " & Number.Text & "is" & Str(Rev)
End Select
End Sub
0 comments:
Post a Comment