Public Class Class1 Dim n, fact As Integer Sub New() Console.Write("Enter a Number : ") n = CInt(Console.ReadLine()) End Sub Sub checking() If n < 0 Then Console.WriteLine("Factorial of negative number is NOT possible.") ElseIf n = 0 Or n = 1 Then Console.WriteLine("Factorial of " + n.ToString + " = 1") Else : fact = factorial(n) Console.WriteLine("Factorial of " + n.ToString + " = " + fact.ToString()) End If End Sub Function factorial(ByVal m As Integer) As Integer If m = 0 Then Return 1 Else Return m * factorial(m - 1) End If End Function End Class Module FactUsClass Sub Main() Dim obj As New Class1 obj.checking() Console.ReadLine() End Sub End Module
Visual Basic dot net VB.net programming microsoft .net framework object oriented language network enabled technology visual basic 2005 IDE integrated development environment console application microsoft cre common runtime environment
Factorial Using Class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment