0% found this document useful (0 votes)
21 views3 pages

VB Prog Sin Cos Evenodd Fact Prime

Visual basic programming program help in the exam pr

Uploaded by

yashlanjewar370
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)
21 views3 pages

VB Prog Sin Cos Evenodd Fact Prime

Visual basic programming program help in the exam pr

Uploaded by

yashlanjewar370
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/ 3

‘Program in VB for computing Sin x, Cos x, Even/Odd, Factorial, prime/Not Prime Number.

Properties:

Coding:

Private Sub cmd_evenodd_Click()


Dim num As Integer
num = InputBox("Enter a number : ", 100, 100)
If num Mod 2 = 0 Then
MsgBox ("Entered number " & num & " is an even number.....")
Else
MsgBox ("Entered number " & num & " is an odd number.....")
End If
End Sub

Private Sub cmd_fact_Click()


Dim n, i As Integer
Dim f As Long: f = 1
n = InputBox("Enter a number : ")
For i = 1 To n
f=f*i
Next
MsgBox "Factorial of entered number = " & f

End Sub

Private Sub cmd_prime_Click()


Dim flag As Boolean
Dim n As Integer
n = InputBox("Enter a number : ")
flag = False
For i = 2 To n - 1
If n Mod i = 0 Then
flag = True
Exit For
End If
Next

If flag = False Then


MsgBox ("Entered number " & n & " is a prime number.....")
Else
MsgBox ("Entered number " & n & " is not a prime number number.....")
End If

End Sub

Private Sub cmd_sine_Click()


Dim X As Double
Dim n As Integer
Dim sum_pos, sum_neg, tot_sum As Double: sum_pos = 0: sum_neg = 0: tot_sum = 0
X = InputBox("Enter the value of x : ")
n = InputBox("Enter value of n : ")

Dim i As Integer

For i = 1 To n Step 4
sum_pos = sum_pos + (power(X, i) / fact(i))
Next i

Dim j As Integer

For j = 3 To n Step 4
sum_neg = sum_neg + (power(X, j) / fact(j))
Next j

tot_sum = sum_pos - sum_neg


MsgBox "Value of sin(" & X & ")=" & tot_sum
End Sub

Private Sub cmd_cos_Click()


Dim X As Double
Dim n As Integer
Dim sum_pos, sum_neg, tot_sum As Double: sum_pos = 0: sum_neg = 0: tot_sum = 0
X = InputBox("Enter the value of x : ")
n = InputBox("Enter value of n : ")

Dim i As Integer

For i = 0 To n Step 4
sum_pos = sum_pos + (power(X, i) / fact(i))
Next i

Dim j As Integer

For j = 2 To n Step 4
sum_neg = sum_neg + (power(X, j) / fact(j))
Next j

tot_sum = sum_pos - sum_neg


MsgBox "Value of cos(" & X & ")=" & tot_sum
End Sub

Public Function power(ByVal x1 As Double, ByVal y As Integer)


Dim p As Double: p = 1
Dim ii As Integer
For ii = 1 To y
p = p * x1
Next ii
power = p 'returning value

End Function
Public Function fact(ByVal x2 As Integer)
Dim f As Double: f = 1
Dim i1 As Integer
If x2 = 0 Then
f=1
Else
For i1 = 1 To x2
f = f * i1
Next i1
End If
fact = f 'returning value
End Function
OUTPUT:

You might also like